blob: 48aed7a17c08af311971b86d7cd2d1015acfecbb [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"
joshualitte76b4bb32015-12-28 07:23:58 -080016#include "SkGlyphCache.h"
Mike Reed80747ef2018-01-23 15:29:32 -050017#include "SkMaskFilterBase.h"
Herb Derbyeb3f6742018-03-05 14:36:45 -050018#include "SkPaintPriv.h"
Jim Van Verth54d9c882018-02-08 16:14:48 -050019#include "SkTextToPathIter.h"
Brian Salomon89527432016-12-16 09:52:16 -050020#include "ops/GrAtlasTextOp.h"
Ben Wagner75d6db72018-09-20 14:39:39 -040021
Mike Klein79aea6a2018-06-11 10:45:26 -040022#include <new>
joshualitt2e2202e2015-12-10 11:22:08 -080023
Ben Wagner75d6db72018-09-20 14:39:39 -040024template <size_t N> static size_t sk_align(size_t s) {
25 return ((s + (N-1)) / N) * N;
26}
27
Herb Derby86240592018-05-24 16:12:31 -040028sk_sp<GrTextBlob> GrTextBlob::Make(int glyphCount, int runCount) {
29 // We allocate size for the GrTextBlob itself, plus size for the vertices array,
joshualitt92303772016-02-10 11:55:52 -080030 // and size for the glyphIds array.
31 size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
Ben Wagner75d6db72018-09-20 14:39:39 -040032
Herb Derbyf7d5d742018-11-16 13:24:32 -050033 size_t blobStart = 0;
34 size_t vertex = sk_align<alignof(char)> (blobStart + sizeof(GrTextBlob) * 1);
Ben Wagner75d6db72018-09-20 14:39:39 -040035 size_t glyphs = sk_align<alignof(GrGlyph*)> (vertex + sizeof(char) * verticesCount);
36 size_t runs = sk_align<alignof(GrTextBlob::Run)>(glyphs + sizeof(GrGlyph*) * glyphCount);
37 size_t size = (runs + sizeof(GrTextBlob::Run) * runCount);
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 Derbyf7d5d742018-11-16 13:24:32 -050045 sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{}};
46 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);
50 blob->fGlyphs = SkTAddOffset<GrGlyph*>(blob.get(), glyphs);
51 blob->fRuns = SkTAddOffset<GrTextBlob::Run>(blob.get(), runs);
joshualitt92303772016-02-10 11:55:52 -080052
53 // Initialize runs
54 for (int i = 0; i < runCount; i++) {
Herb Derbyf7d5d742018-11-16 13:24:32 -050055 new (&blob->fRuns[i]) GrTextBlob::Run{blob.get()};
joshualitt92303772016-02-10 11:55:52 -080056 }
Herb Derbyf7d5d742018-11-16 13:24:32 -050057 blob->fRunCountLimit = runCount;
58 return blob;
joshualitt92303772016-02-10 11:55:52 -080059}
60
Herb Derby2bb343c2018-11-08 15:03:48 -050061SkExclusiveStrikePtr GrTextBlob::Run::setupCache(const SkPaint& skPaint,
62 const SkSurfaceProps& props,
63 SkScalerContextFlags scalerContextFlags,
64 const SkMatrix& viewMatrix) {
joshualitte76b4bb32015-12-28 07:23:58 -080065
66 // if we have an override descriptor for the run, then we should use that
Herb Derby317adf72018-11-16 17:29:29 -050067 SkAutoDescriptor* desc = fARGBFallbackDescriptor.get() ? fARGBFallbackDescriptor.get() : &fDescriptor;
bsalomon8b6fa5e2016-05-19 16:23:47 -070068 SkScalerContextEffects effects;
Herb Derby980a48d2018-01-23 13:39:21 -050069 SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
Herb Derbyc3415002018-11-08 16:40:26 -050070 skPaint, props, scalerContextFlags, viewMatrix, desc, &effects);
Herb Derby2bb343c2018-11-08 15:03:48 -050071 fTypeface = SkPaintPriv::RefTypefaceOrDefault(skPaint);
72 fPathEffect = sk_ref_sp(effects.fPathEffect);
73 fMaskFilter = sk_ref_sp(effects.fMaskFilter);
74 return SkStrikeCache::FindOrCreateStrikeExclusive(*desc->getDesc(), effects, *fTypeface);
joshualitte76b4bb32015-12-28 07:23:58 -080075}
76
Herb Derby2bb343c2018-11-08 15:03:48 -050077void GrTextBlob::Run::appendPathGlyph(const SkPath& path, SkPoint position,
Jim Van Verth54d9c882018-02-08 16:14:48 -050078 SkScalar scale, bool preTransformed) {
Herb Derby2bb343c2018-11-08 15:03:48 -050079 fPathGlyphs.push_back(PathGlyph(path, position.x(), position.y(), scale, preTransformed));
joshualitta06e6ab2015-12-10 08:54:41 -080080}
81
Herb Derby0edb2142018-10-16 17:04:11 -040082bool GrTextBlob::mustRegenerate(const SkPaint& paint, bool anyRunHasSubpixelPosition,
83 const SkMaskFilterBase::BlurRec& blurRec,
84 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
joshualittfd5f6c12015-12-10 07:44:50 -080085 // If we have LCD text then our canonical color will be set to transparent, in this case we have
86 // to regenerate the blob on any color change
87 // We use the grPaint to get any color filter effects
88 if (fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
Herb Derbybc6f9c92018-08-08 13:58:45 -040089 fLuminanceColor != paint.computeLuminanceColor()) {
joshualittfd5f6c12015-12-10 07:44:50 -080090 return true;
91 }
92
joshualitt8e0ef292016-02-19 14:13:03 -080093 if (fInitialViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) {
joshualittfd5f6c12015-12-10 07:44:50 -080094 return true;
95 }
96
Brian Salomon5c6ac642017-12-19 11:09:32 -050097 /** This could be relaxed for blobs with only distance field glyphs. */
joshualitt8e0ef292016-02-19 14:13:03 -080098 if (fInitialViewMatrix.hasPerspective() && !fInitialViewMatrix.cheapEqualTo(viewMatrix)) {
joshualittfd5f6c12015-12-10 07:44:50 -080099 return true;
100 }
101
102 // We only cache one masked version
103 if (fKey.fHasBlur &&
Mike Reed1be1f8d2018-03-14 13:01:17 -0400104 (fBlurRec.fSigma != blurRec.fSigma || fBlurRec.fStyle != blurRec.fStyle)) {
joshualittfd5f6c12015-12-10 07:44:50 -0800105 return true;
106 }
107
108 // Similarly, we only cache one version for each style
109 if (fKey.fStyle != SkPaint::kFill_Style &&
Herb Derbybc6f9c92018-08-08 13:58:45 -0400110 (fStrokeInfo.fFrameWidth != paint.getStrokeWidth() ||
111 fStrokeInfo.fMiterLimit != paint.getStrokeMiter() ||
112 fStrokeInfo.fJoin != paint.getStrokeJoin())) {
joshualittfd5f6c12015-12-10 07:44:50 -0800113 return true;
114 }
115
116 // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls
117 // for mixed blobs if this becomes an issue.
118 if (this->hasBitmap() && this->hasDistanceField()) {
119 // Identical viewmatrices and we can reuse in all cases
joshualitt8e0ef292016-02-19 14:13:03 -0800120 if (fInitialViewMatrix.cheapEqualTo(viewMatrix) && x == fInitialX && y == fInitialY) {
joshualittfd5f6c12015-12-10 07:44:50 -0800121 return false;
122 }
123 return true;
124 }
125
126 if (this->hasBitmap()) {
joshualitt8e0ef292016-02-19 14:13:03 -0800127 if (fInitialViewMatrix.getScaleX() != viewMatrix.getScaleX() ||
128 fInitialViewMatrix.getScaleY() != viewMatrix.getScaleY() ||
129 fInitialViewMatrix.getSkewX() != viewMatrix.getSkewX() ||
130 fInitialViewMatrix.getSkewY() != viewMatrix.getSkewY()) {
joshualittfd5f6c12015-12-10 07:44:50 -0800131 return true;
132 }
133
Herb Derbycb65ce72018-10-17 11:39:41 -0400134 // If the text blob only has full pixel glyphs, then fractional part of the position does
135 // not affect the SkGlyphs used.
136 if (anyRunHasSubpixelPosition) {
137 // We can update the positions in the text blob without regenerating the whole
Herb Derby0edb2142018-10-16 17:04:11 -0400138 // blob, but only for integer translations.
139 // This cool bit of math will determine the necessary translation to apply to the
140 // already generated vertex coordinates to move them to the correct position.
141 SkScalar transX = viewMatrix.getTranslateX() +
142 viewMatrix.getScaleX() * (x - fInitialX) +
143 viewMatrix.getSkewX() * (y - fInitialY) -
144 fInitialViewMatrix.getTranslateX();
145 SkScalar transY = viewMatrix.getTranslateY() +
146 viewMatrix.getSkewY() * (x - fInitialX) +
147 viewMatrix.getScaleY() * (y - fInitialY) -
148 fInitialViewMatrix.getTranslateY();
149 if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY)) {
150 return true;
151 }
joshualittfd5f6c12015-12-10 07:44:50 -0800152 }
joshualittfd5f6c12015-12-10 07:44:50 -0800153 } else if (this->hasDistanceField()) {
154 // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different
155 // distance field being generated, so we have to regenerate in those cases
156 SkScalar newMaxScale = viewMatrix.getMaxScale();
joshualitt8e0ef292016-02-19 14:13:03 -0800157 SkScalar oldMaxScale = fInitialViewMatrix.getMaxScale();
joshualittfd5f6c12015-12-10 07:44:50 -0800158 SkScalar scaleAdjust = newMaxScale / oldMaxScale;
159 if (scaleAdjust < fMaxMinScale || scaleAdjust > fMinMaxScale) {
160 return true;
161 }
joshualittfd5f6c12015-12-10 07:44:50 -0800162 }
163
joshualittfd5f6c12015-12-10 07:44:50 -0800164 // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case
165 // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate
166 // the blob anyways at flush time, so no need to regenerate explicitly
167 return false;
168}
169
Herb Derby86240592018-05-24 16:12:31 -0400170inline std::unique_ptr<GrAtlasTextOp> GrTextBlob::makeOp(
Herb Derby69ff8952018-11-12 11:39:12 -0500171 const SubRun& info, int glyphCount, uint16_t run, uint16_t subRun,
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400172 const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect,
Brian Osmancf860852018-10-31 14:04:39 -0400173 const SkPaint& paint, const SkPMColor4f& filteredColor, const SkSurfaceProps& props,
Herb Derbyc1b482c2018-08-09 15:02:27 -0400174 const GrDistanceFieldAdjustTable* distanceAdjustTable, GrTextTarget* target) {
joshualitt2e2202e2015-12-10 11:22:08 -0800175 GrMaskFormat format = info.maskFormat();
joshualitt2e2202e2015-12-10 11:22:08 -0800176
Brian Salomon44acb5b2017-07-18 19:59:24 -0400177 GrPaint grPaint;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400178 target->makeGrPaint(info.maskFormat(), paint, viewMatrix, &grPaint);
Brian Salomonf8334782017-01-03 09:42:58 -0500179 std::unique_ptr<GrAtlasTextOp> op;
joshualitt2e2202e2015-12-10 11:22:08 -0800180 if (info.drawAsDistanceFields()) {
Brian Osman34ec3742018-07-03 10:40:57 -0400181 // TODO: Can we be even smarter based on the dest transfer function?
Brian Salomon44acb5b2017-07-18 19:59:24 -0400182 op = GrAtlasTextOp::MakeDistanceField(
Robert Phillips7c525e62018-06-12 10:11:12 -0400183 target->getContext(), std::move(grPaint), glyphCount, distanceAdjustTable,
Herb Derbybc6f9c92018-08-08 13:58:45 -0400184 target->colorSpaceInfo().isLinearlyBlended(), paint.computeLuminanceColor(),
Ben Wagner4c329562018-04-18 16:04:46 -0400185 props, info.isAntiAliased(), info.hasUseLCDText());
joshualitt2e2202e2015-12-10 11:22:08 -0800186 } else {
Robert Phillips7c525e62018-06-12 10:11:12 -0400187 op = GrAtlasTextOp::MakeBitmap(target->getContext(), std::move(grPaint), format, glyphCount,
Jim Van Verthb515ae72018-05-23 16:44:55 -0400188 info.needsTransform());
joshualitt2e2202e2015-12-10 11:22:08 -0800189 }
Brian Salomon09d994e2016-12-21 11:14:46 -0500190 GrAtlasTextOp::Geometry& geometry = op->geometry();
joshualitt8e0ef292016-02-19 14:13:03 -0800191 geometry.fViewMatrix = viewMatrix;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400192 geometry.fClipRect = clipRect;
joshualitt2e2202e2015-12-10 11:22:08 -0800193 geometry.fBlob = SkRef(this);
194 geometry.fRun = run;
195 geometry.fSubRun = subRun;
Brian Osmancf860852018-10-31 14:04:39 -0400196 geometry.fColor = info.maskFormat() == kARGB_GrMaskFormat ? SK_PMColor4fWHITE : filteredColor;
joshualitt8e0ef292016-02-19 14:13:03 -0800197 geometry.fX = x;
198 geometry.fY = y;
Brian Salomon09d994e2016-12-21 11:14:46 -0500199 op->init();
Brian Salomonf18b1d82017-10-27 11:30:49 -0400200 return op;
joshualitt2e2202e2015-12-10 11:22:08 -0800201}
202
joshualitt8e0ef292016-02-19 14:13:03 -0800203static void calculate_translation(bool applyVM,
204 const SkMatrix& newViewMatrix, SkScalar newX, SkScalar newY,
205 const SkMatrix& currentViewMatrix, SkScalar currentX,
206 SkScalar currentY, SkScalar* transX, SkScalar* transY) {
207 if (applyVM) {
208 *transX = newViewMatrix.getTranslateX() +
209 newViewMatrix.getScaleX() * (newX - currentX) +
210 newViewMatrix.getSkewX() * (newY - currentY) -
211 currentViewMatrix.getTranslateX();
212
213 *transY = newViewMatrix.getTranslateY() +
214 newViewMatrix.getSkewY() * (newX - currentX) +
215 newViewMatrix.getScaleY() * (newY - currentY) -
216 currentViewMatrix.getTranslateY();
217 } else {
218 *transX = newX - currentX;
219 *transY = newY - currentY;
220 }
221}
222
Herb Derbyc1b482c2018-08-09 15:02:27 -0400223void GrTextBlob::flush(GrTextTarget* target, const SkSurfaceProps& props,
224 const GrDistanceFieldAdjustTable* distanceAdjustTable,
Brian Osmancf860852018-10-31 14:04:39 -0400225 const SkPaint& paint, const SkPMColor4f& filteredColor, const GrClip& clip,
Robert Phillipse4643cc2018-08-14 13:01:29 -0400226 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
Jim Van Verth54d9c882018-02-08 16:14:48 -0500227
Herb Derby86240592018-05-24 16:12:31 -0400228 // GrTextBlob::makeOp only takes uint16_t values for run and subRun indices.
Jim Van Verth54d9c882018-02-08 16:14:48 -0500229 // Encountering something larger than this is highly unlikely, so we'll just not draw it.
Herb Derby2bb343c2018-11-08 15:03:48 -0500230 int lastRun = SkTMin(fRunCountLimit, (1 << 16)) - 1;
Herb Derbydac1ed52018-09-12 17:04:21 -0400231 // For each run in the GrTextBlob we're going to churn through all the glyphs.
232 // Each run is broken into a path part and a Mask / DFT / ARGB part.
Jim Van Verth54d9c882018-02-08 16:14:48 -0500233 for (int runIndex = 0; runIndex <= lastRun; runIndex++) {
Herb Derbydac1ed52018-09-12 17:04:21 -0400234
Jim Van Verth54d9c882018-02-08 16:14:48 -0500235 Run& run = fRuns[runIndex];
236
237 // first flush any path glyphs
238 if (run.fPathGlyphs.count()) {
Herb Derbydac1ed52018-09-12 17:04:21 -0400239 SkPaint runPaint{paint};
Mike Reed48b958b2018-12-03 13:09:02 -0500240 runPaint.setAntiAlias(run.fAntiAlias);
Herb Derby9f491482018-08-08 11:53:00 -0400241
Jim Van Verth54d9c882018-02-08 16:14:48 -0500242 for (int i = 0; i < run.fPathGlyphs.count(); i++) {
Herb Derby86240592018-05-24 16:12:31 -0400243 GrTextBlob::Run::PathGlyph& pathGlyph = run.fPathGlyphs[i];
Robert Phillips137ca522018-08-15 10:14:33 -0400244
Herb Derbydac1ed52018-09-12 17:04:21 -0400245 SkMatrix ctm;
Robert Phillips137ca522018-08-15 10:14:33 -0400246 const SkPath* path = &pathGlyph.fPath;
Herb Derbydac1ed52018-09-12 17:04:21 -0400247
248 // TmpPath must be in the same scope as GrShape shape below.
Robert Phillips137ca522018-08-15 10:14:33 -0400249 SkTLazy<SkPath> tmpPath;
250
Herb Derbydac1ed52018-09-12 17:04:21 -0400251 // The glyph positions and glyph outlines are either in device space or in source
252 // space based on fPreTransformed.
253 if (!pathGlyph.fPreTransformed) {
254 // Positions and outlines are in source space.
Robert Phillips137ca522018-08-15 10:14:33 -0400255
Herb Derbydac1ed52018-09-12 17:04:21 -0400256 ctm = viewMatrix;
Robert Phillipsd20d2612018-08-28 10:09:01 -0400257
Herb Derbydac1ed52018-09-12 17:04:21 -0400258 SkMatrix pathMatrix = SkMatrix::MakeScale(pathGlyph.fScale, pathGlyph.fScale);
Robert Phillipsd20d2612018-08-28 10:09:01 -0400259
Herb Derbydac1ed52018-09-12 17:04:21 -0400260 // The origin for the blob may have changed, so figure out the delta.
261 SkVector originShift = SkPoint{x, y} - SkPoint{fInitialX, fInitialY};
262
263 // Shift the original glyph location in source space to the position of the new
264 // blob.
265 pathMatrix.postTranslate(originShift.x() + pathGlyph.fX,
266 originShift.y() + pathGlyph.fY);
267
268 // If there are shaders, blurs or styles, the path must be scaled into source
269 // space independently of the CTM. This allows the CTM to be correct for the
270 // different effects.
271 GrStyle style(runPaint);
272 bool scalePath = runPaint.getShader()
273 || style.applies()
274 || runPaint.getMaskFilter();
275 if (!scalePath) {
276 // Scale can be applied to CTM -- no effects.
277
278 ctm.preConcat(pathMatrix);
279 } else {
280 // Scale the outline into source space.
281
282 // Transform the path form the normalized outline to source space. This
283 // way the CTM will remain the same so it can be used by the effects.
284 SkPath* sourceOutline = tmpPath.init();
285 path->transform(pathMatrix, sourceOutline);
286 sourceOutline->setIsVolatile(true);
287 path = sourceOutline;
288 }
289
290
Robert Phillipsd20d2612018-08-28 10:09:01 -0400291 } else {
Herb Derbydac1ed52018-09-12 17:04:21 -0400292 // Positions and outlines are in device space.
293
294 SkPoint originalOrigin = {fInitialX, fInitialY};
295 fInitialViewMatrix.mapPoints(&originalOrigin, 1);
296
297 SkPoint newOrigin = {x, y};
298 viewMatrix.mapPoints(&newOrigin, 1);
299
300 // The origin shift in device space.
301 SkPoint originShift = newOrigin - originalOrigin;
302
303 // Shift the original glyph location in device space to the position of the
304 // new blob.
305 ctm = SkMatrix::MakeTrans(originShift.x() + pathGlyph.fX,
306 originShift.y() + pathGlyph.fY);
Robert Phillips137ca522018-08-15 10:14:33 -0400307 }
308
Robert Phillips46a13382018-08-23 13:53:01 -0400309 // TODO: we are losing the mutability of the path here
310 GrShape shape(*path, paint);
311
Herb Derbydac1ed52018-09-12 17:04:21 -0400312 target->drawShape(clip, runPaint, ctm, shape);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500313 }
joshualitt2e2202e2015-12-10 11:22:08 -0800314 }
joshualitt2e2202e2015-12-10 11:22:08 -0800315
Jim Van Verth54d9c882018-02-08 16:14:48 -0500316 // then flush each subrun, if any
317 if (!run.fInitialized) {
Jim Van Verth89737de2018-02-06 21:30:20 +0000318 continue;
319 }
Herb Derbydac1ed52018-09-12 17:04:21 -0400320
Jim Van Verth54d9c882018-02-08 16:14:48 -0500321 int lastSubRun = SkTMin(run.fSubRunInfo.count(), 1 << 16) - 1;
322 for (int subRun = 0; subRun <= lastSubRun; subRun++) {
Herb Derby69ff8952018-11-12 11:39:12 -0500323 const SubRun& info = run.fSubRunInfo[subRun];
Jim Van Verth54d9c882018-02-08 16:14:48 -0500324 int glyphCount = info.glyphCount();
325 if (0 == glyphCount) {
326 continue;
327 }
328
329 bool skipClip = false;
330 bool submitOp = true;
331 SkIRect clipRect = SkIRect::MakeEmpty();
332 SkRect rtBounds = SkRect::MakeWH(target->width(), target->height());
333 SkRRect clipRRect;
334 GrAA aa;
Jim Van Verthb515ae72018-05-23 16:44:55 -0400335 // We can clip geometrically if we're not using SDFs or transformed glyphs,
Jim Van Verth54d9c882018-02-08 16:14:48 -0500336 // and we have an axis-aligned rectangular non-AA clip
Jim Van Verthb515ae72018-05-23 16:44:55 -0400337 if (!info.drawAsDistanceFields() && !info.needsTransform() &&
Jim Van Verthcf838c72018-03-05 14:40:36 -0500338 clip.isRRect(rtBounds, &clipRRect, &aa) &&
Jim Van Verth54d9c882018-02-08 16:14:48 -0500339 clipRRect.isRect() && GrAA::kNo == aa) {
340 skipClip = true;
341 // We only need to do clipping work if the subrun isn't contained by the clip
342 SkRect subRunBounds;
Jim Van Verth70276912018-06-01 13:46:46 -0400343 this->computeSubRunBounds(&subRunBounds, runIndex, subRun, viewMatrix, x, y,
344 false);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500345 if (!clipRRect.getBounds().contains(subRunBounds)) {
346 // If the subrun is completely outside, don't add an op for it
347 if (!clipRRect.getBounds().intersects(subRunBounds)) {
348 submitOp = false;
349 }
350 else {
351 clipRRect.getBounds().round(&clipRect);
352 }
353 }
354 }
355
356 if (submitOp) {
357 auto op = this->makeOp(info, glyphCount, runIndex, subRun, viewMatrix, x, y,
Herb Derbybc6f9c92018-08-08 13:58:45 -0400358 clipRect, paint, filteredColor, props, distanceAdjustTable,
Robert Phillips5a66efb2018-03-07 15:13:18 -0500359 target);
Jim Van Verth54d9c882018-02-08 16:14:48 -0500360 if (op) {
361 if (skipClip) {
362 target->addDrawOp(GrNoClip(), std::move(op));
363 }
364 else {
365 target->addDrawOp(clip, std::move(op));
366 }
367 }
368 }
369 }
370
Jim Van Verth89737de2018-02-06 21:30:20 +0000371 }
Jim Van Verth89737de2018-02-06 21:30:20 +0000372}
373
Herb Derby86240592018-05-24 16:12:31 -0400374std::unique_ptr<GrDrawOp> GrTextBlob::test_makeOp(
Jim Van Verth56c37142017-10-31 14:44:25 -0400375 int glyphCount, uint16_t run, uint16_t subRun, const SkMatrix& viewMatrix,
Brian Osmancf860852018-10-31 14:04:39 -0400376 SkScalar x, SkScalar y, const SkPaint& paint, const SkPMColor4f& filteredColor,
Herb Derbybc6f9c92018-08-08 13:58:45 -0400377 const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable,
Herb Derbyc1b482c2018-08-09 15:02:27 -0400378 GrTextTarget* target) {
Herb Derby69ff8952018-11-12 11:39:12 -0500379 const GrTextBlob::SubRun& info = fRuns[run].fSubRunInfo[subRun];
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400380 SkIRect emptyRect = SkIRect::MakeEmpty();
Herb Derbybc6f9c92018-08-08 13:58:45 -0400381 return this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, emptyRect,
382 paint, filteredColor, props, distanceAdjustTable, target);
joshualitt323c2eb2016-01-20 06:48:47 -0800383}
joshualitt2e2202e2015-12-10 11:22:08 -0800384
Herb Derby86240592018-05-24 16:12:31 -0400385void GrTextBlob::AssertEqual(const GrTextBlob& l, const GrTextBlob& r) {
joshualitt2f2ee832016-02-10 08:52:24 -0800386 SkASSERT_RELEASE(l.fSize == r.fSize);
joshualitt259fbf12015-07-21 11:39:34 -0700387
joshualitt2f2ee832016-02-10 08:52:24 -0800388 SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
389 SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
joshualitt259fbf12015-07-21 11:39:34 -0700390
joshualitt2f2ee832016-02-10 08:52:24 -0800391 SkASSERT_RELEASE(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth);
392 SkASSERT_RELEASE(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit);
393 SkASSERT_RELEASE(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin);
joshualitt259fbf12015-07-21 11:39:34 -0700394
joshualitt2f2ee832016-02-10 08:52:24 -0800395 SkASSERT_RELEASE(l.fKey == r.fKey);
joshualitt2f2ee832016-02-10 08:52:24 -0800396 //SkASSERT_RELEASE(l.fPaintColor == r.fPaintColor); // Colors might not actually be identical
397 SkASSERT_RELEASE(l.fMaxMinScale == r.fMaxMinScale);
398 SkASSERT_RELEASE(l.fMinMaxScale == r.fMinMaxScale);
399 SkASSERT_RELEASE(l.fTextType == r.fTextType);
joshualitt259fbf12015-07-21 11:39:34 -0700400
Herb Derby2bb343c2018-11-08 15:03:48 -0500401 SkASSERT_RELEASE(l.fRunCountLimit == r.fRunCountLimit);
402 for (int i = 0; i < l.fRunCountLimit; i++) {
joshualitt259fbf12015-07-21 11:39:34 -0700403 const Run& lRun = l.fRuns[i];
404 const Run& rRun = r.fRuns[i];
405
joshualitt259fbf12015-07-21 11:39:34 -0700406 if (lRun.fTypeface.get()) {
joshualitt2f2ee832016-02-10 08:52:24 -0800407 SkASSERT_RELEASE(rRun.fTypeface.get());
Hal Canary144caf52016-11-07 17:57:18 -0500408 SkASSERT_RELEASE(SkTypeface::Equal(lRun.fTypeface.get(), rRun.fTypeface.get()));
joshualitt259fbf12015-07-21 11:39:34 -0700409 } else {
joshualitt2f2ee832016-02-10 08:52:24 -0800410 SkASSERT_RELEASE(!rRun.fTypeface.get());
joshualitt259fbf12015-07-21 11:39:34 -0700411 }
412
joshualitt259fbf12015-07-21 11:39:34 -0700413
joshualitt2f2ee832016-02-10 08:52:24 -0800414 SkASSERT_RELEASE(lRun.fDescriptor.getDesc());
415 SkASSERT_RELEASE(rRun.fDescriptor.getDesc());
bsalomonc5d07fa2016-05-17 10:17:45 -0700416 SkASSERT_RELEASE(*lRun.fDescriptor.getDesc() == *rRun.fDescriptor.getDesc());
joshualitt259fbf12015-07-21 11:39:34 -0700417
Herb Derby317adf72018-11-16 17:29:29 -0500418 if (lRun.fARGBFallbackDescriptor.get()) {
419 SkASSERT_RELEASE(lRun.fARGBFallbackDescriptor->getDesc());
420 SkASSERT_RELEASE(rRun.fARGBFallbackDescriptor.get() && rRun.fARGBFallbackDescriptor->getDesc());
421 SkASSERT_RELEASE(*lRun.fARGBFallbackDescriptor->getDesc() ==
422 *rRun.fARGBFallbackDescriptor->getDesc());
joshualitt259fbf12015-07-21 11:39:34 -0700423 } else {
Herb Derby317adf72018-11-16 17:29:29 -0500424 SkASSERT_RELEASE(!rRun.fARGBFallbackDescriptor.get());
joshualitt259fbf12015-07-21 11:39:34 -0700425 }
426
427 // color can be changed
428 //SkASSERT(lRun.fColor == rRun.fColor);
joshualitt2f2ee832016-02-10 08:52:24 -0800429 SkASSERT_RELEASE(lRun.fInitialized == rRun.fInitialized);
joshualitt259fbf12015-07-21 11:39:34 -0700430
joshualitt2f2ee832016-02-10 08:52:24 -0800431 SkASSERT_RELEASE(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count());
joshualitt259fbf12015-07-21 11:39:34 -0700432 for(int j = 0; j < lRun.fSubRunInfo.count(); j++) {
Herb Derby69ff8952018-11-12 11:39:12 -0500433 const SubRun& lSubRun = lRun.fSubRunInfo[j];
434 const SubRun& rSubRun = rRun.fSubRunInfo[j];
joshualitt259fbf12015-07-21 11:39:34 -0700435
joshualitt2f2ee832016-02-10 08:52:24 -0800436 // TODO we can do this check, but we have to apply the VM to the old vertex bounds
437 //SkASSERT_RELEASE(lSubRun.vertexBounds() == rSubRun.vertexBounds());
joshualitt259fbf12015-07-21 11:39:34 -0700438
joshualitt2f2ee832016-02-10 08:52:24 -0800439 if (lSubRun.strike()) {
440 SkASSERT_RELEASE(rSubRun.strike());
Robert Phillipscaf1ebb2018-03-01 14:28:44 -0500441 SkASSERT_RELEASE(GrTextStrike::GetKey(*lSubRun.strike()) ==
442 GrTextStrike::GetKey(*rSubRun.strike()));
joshualitt2f2ee832016-02-10 08:52:24 -0800443
444 } else {
445 SkASSERT_RELEASE(!rSubRun.strike());
446 }
447
448 SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIndex());
449 SkASSERT_RELEASE(lSubRun.vertexEndIndex() == rSubRun.vertexEndIndex());
450 SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartIndex());
451 SkASSERT_RELEASE(lSubRun.glyphEndIndex() == rSubRun.glyphEndIndex());
452 SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat());
453 SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDistanceFields());
454 SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText());
joshualitt259fbf12015-07-21 11:39:34 -0700455 }
Jim Van Verth54d9c882018-02-08 16:14:48 -0500456
457 SkASSERT_RELEASE(lRun.fPathGlyphs.count() == rRun.fPathGlyphs.count());
458 for (int i = 0; i < lRun.fPathGlyphs.count(); i++) {
459 const Run::PathGlyph& lPathGlyph = lRun.fPathGlyphs[i];
460 const Run::PathGlyph& rPathGlyph = rRun.fPathGlyphs[i];
461
462 SkASSERT_RELEASE(lPathGlyph.fPath == rPathGlyph.fPath);
463 // We can't assert that these have the same translations
464 }
joshualitt259fbf12015-07-21 11:39:34 -0700465 }
466}
joshualitt8e0ef292016-02-19 14:13:03 -0800467
Herb Derby69ff8952018-11-12 11:39:12 -0500468void GrTextBlob::SubRun::computeTranslation(const SkMatrix& viewMatrix,
469 SkScalar x, SkScalar y, SkScalar* transX,
470 SkScalar* transY) {
joshualitt8e0ef292016-02-19 14:13:03 -0800471 calculate_translation(!this->drawAsDistanceFields(), viewMatrix, x, y,
472 fCurrentViewMatrix, fX, fY, transX, transY);
473 fCurrentViewMatrix = viewMatrix;
474 fX = x;
475 fY = y;
476}