blob: 12ad89a62a8749a2677df4696e89d4c0ae57a0ed [file] [log] [blame]
joshualitt259fbf12015-07-21 11:39:34 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "GrAtlasTextBlob.h"
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"
joshualitt0a42e682015-12-10 13:20:58 -080012#include "GrTextUtils.h"
joshualitt2e2202e2015-12-10 11:22:08 -080013#include "SkColorFilter.h"
14#include "SkDrawFilter.h"
joshualitte76b4bb32015-12-28 07:23:58 -080015#include "SkGlyphCache.h"
Mike Reed80747ef2018-01-23 15:29:32 -050016#include "SkMaskFilterBase.h"
joshualitt2e2202e2015-12-10 11:22:08 -080017#include "SkTextBlobRunIterator.h"
Brian Salomon89527432016-12-16 09:52:16 -050018#include "ops/GrAtlasTextOp.h"
joshualitt2e2202e2015-12-10 11:22:08 -080019
Florin Malitac337c9e2017-03-10 18:02:29 +000020sk_sp<GrAtlasTextBlob> GrAtlasTextBlob::Make(GrMemoryPool* pool, int glyphCount, int runCount) {
joshualitt92303772016-02-10 11:55:52 -080021 // We allocate size for the GrAtlasTextBlob itself, plus size for the vertices array,
22 // and size for the glyphIds array.
23 size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
24 size_t size = sizeof(GrAtlasTextBlob) +
25 verticesCount +
26 glyphCount * sizeof(GrGlyph**) +
27 sizeof(GrAtlasTextBlob::Run) * runCount;
28
29 void* allocation = pool->allocate(size);
30 if (CACHE_SANITY_CHECK) {
31 sk_bzero(allocation, size);
32 }
33
Florin Malitac337c9e2017-03-10 18:02:29 +000034 sk_sp<GrAtlasTextBlob> cacheBlob(new (allocation) GrAtlasTextBlob);
joshualitt92303772016-02-10 11:55:52 -080035 cacheBlob->fSize = size;
36
37 // setup offsets for vertices / glyphs
Brian Salomon18923f92017-11-06 16:26:02 -050038 cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<char*>(cacheBlob.get());
joshualitt92303772016-02-10 11:55:52 -080039 cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + verticesCount);
40 cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyphs + glyphCount);
41
42 // Initialize runs
43 for (int i = 0; i < runCount; i++) {
44 new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run;
45 }
46 cacheBlob->fRunCount = runCount;
47 cacheBlob->fPool = pool;
48 return cacheBlob;
49}
50
joshualitte76b4bb32015-12-28 07:23:58 -080051SkGlyphCache* GrAtlasTextBlob::setupCache(int runIndex,
52 const SkSurfaceProps& props,
Herb Derbyd8327a82018-01-22 14:39:27 -050053 SkScalerContextFlags scalerContextFlags,
joshualitte76b4bb32015-12-28 07:23:58 -080054 const SkPaint& skPaint,
bungemanf6d1e602016-02-22 13:20:28 -080055 const SkMatrix* viewMatrix) {
joshualitte76b4bb32015-12-28 07:23:58 -080056 GrAtlasTextBlob::Run* run = &fRuns[runIndex];
57
58 // if we have an override descriptor for the run, then we should use that
59 SkAutoDescriptor* desc = run->fOverrideDescriptor.get() ? run->fOverrideDescriptor.get() :
60 &run->fDescriptor;
bsalomon8b6fa5e2016-05-19 16:23:47 -070061 SkScalerContextEffects effects;
Herb Derby980a48d2018-01-23 13:39:21 -050062 SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
63 skPaint, &props, scalerContextFlags, viewMatrix, desc, &effects);
joshualitte76b4bb32015-12-28 07:23:58 -080064 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface()));
bsalomon8b6fa5e2016-05-19 16:23:47 -070065 run->fPathEffect = sk_ref_sp(effects.fPathEffect);
bsalomon8b6fa5e2016-05-19 16:23:47 -070066 run->fMaskFilter = sk_ref_sp(effects.fMaskFilter);
Hal Canary144caf52016-11-07 17:57:18 -050067 return SkGlyphCache::DetachCache(run->fTypeface.get(), effects, desc->getDesc());
joshualitte76b4bb32015-12-28 07:23:58 -080068}
69
joshualittf528e0d2015-12-09 06:42:52 -080070void GrAtlasTextBlob::appendGlyph(int runIndex,
71 const SkRect& positions,
72 GrColor color,
Brian Salomonf856fd12016-12-16 14:24:34 -050073 GrAtlasTextStrike* strike,
joshualitta06e6ab2015-12-10 08:54:41 -080074 GrGlyph* glyph,
bsalomonc2878e22016-05-17 13:18:03 -070075 SkGlyphCache* cache, const SkGlyph& skGlyph,
Jim Van Verth2fb7c8a2018-02-06 11:14:20 -050076 SkScalar x, SkScalar y, SkScalar scale, bool preTransformed) {
Lee Salzman26d3f212017-01-27 14:31:10 -050077 if (positions.isEmpty()) {
78 return;
79 }
joshualitta06e6ab2015-12-10 08:54:41 -080080
81 // If the glyph is too large we fall back to paths
82 if (glyph->fTooLargeForAtlas) {
Jim Van Verth2fb7c8a2018-02-06 11:14:20 -050083 if (nullptr == glyph->fPath) {
84 const SkPath* glyphPath = cache->findPath(skGlyph);
85 if (!glyphPath) {
86 return;
87 }
88
89 glyph->fPath = new SkPath(*glyphPath);
90 }
91 this->appendPathGlyph(runIndex, *glyph->fPath, x, y, scale, preTransformed);
joshualitta06e6ab2015-12-10 08:54:41 -080092 return;
93 }
94
joshualittf528e0d2015-12-09 06:42:52 -080095 Run& run = fRuns[runIndex];
96 GrMaskFormat format = glyph->fMaskFormat;
97
98 Run::SubRunInfo* subRun = &run.fSubRunInfo.back();
99 if (run.fInitialized && subRun->maskFormat() != format) {
100 subRun = &run.push_back();
101 subRun->setStrike(strike);
102 } else if (!run.fInitialized) {
103 subRun->setStrike(strike);
104 }
105
106 run.fInitialized = true;
107
Brian Salomon5c6ac642017-12-19 11:09:32 -0500108 bool hasW = subRun->hasWCoord();
109 // DF glyphs drawn in perspective must always have a w coord.
110 SkASSERT(hasW || !subRun->drawAsDistanceFields() || !fInitialViewMatrix.hasPerspective());
111 // Non-DF glyphs should never have a w coord.
112 SkASSERT(!hasW || subRun->drawAsDistanceFields());
113
114 size_t vertexStride = GetVertexStride(format, hasW);
joshualittf528e0d2015-12-09 06:42:52 -0800115
116 subRun->setMaskFormat(format);
117
joshualitt7481e752016-01-22 06:08:48 -0800118 subRun->joinGlyphBounds(positions);
joshualittf9e658b2015-12-09 09:26:44 -0800119 subRun->setColor(color);
joshualitt18b072d2015-12-07 12:26:12 -0800120
121 intptr_t vertex = reinterpret_cast<intptr_t>(this->fVertices + subRun->vertexEndIndex());
122
Brian Salomon5c6ac642017-12-19 11:09:32 -0500123 // We always write the third position component used by SDFs. If it is unused it gets
124 // overwritten. Similarly, we always write the color and the blob will later overwrite it
125 // with texture coords if it is unused.
126 size_t colorOffset = hasW ? sizeof(SkPoint3) : sizeof(SkPoint);
127 // V0
128 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fLeft, positions.fTop, 1.f};
129 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
130 vertex += vertexStride;
joshualitt18b072d2015-12-07 12:26:12 -0800131
Brian Salomon5c6ac642017-12-19 11:09:32 -0500132 // V1
133 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fLeft, positions.fBottom, 1.f};
134 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
135 vertex += vertexStride;
joshualitt18b072d2015-12-07 12:26:12 -0800136
Brian Salomon5c6ac642017-12-19 11:09:32 -0500137 // V2
138 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fRight, positions.fTop, 1.f};
139 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
140 vertex += vertexStride;
joshualitt18b072d2015-12-07 12:26:12 -0800141
Brian Salomon5c6ac642017-12-19 11:09:32 -0500142 // V3
143 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fRight, positions.fBottom, 1.f};
144 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
joshualitt18b072d2015-12-07 12:26:12 -0800145
joshualitt18b072d2015-12-07 12:26:12 -0800146 subRun->appendVertices(vertexStride);
147 fGlyphs[subRun->glyphEndIndex()] = glyph;
148 subRun->glyphAppended();
149}
150
Jim Van Verth2fb7c8a2018-02-06 11:14:20 -0500151void GrAtlasTextBlob::appendPathGlyph(int runIndex, const SkPath& path, SkScalar x, SkScalar y,
152 SkScalar scale, bool preTransformed) {
153 Run& run = fRuns[runIndex];
154 run.fPathGlyphs.push_back(GrAtlasTextBlob::Run::PathGlyph(path, x, y, scale, preTransformed));
joshualitta06e6ab2015-12-10 08:54:41 -0800155}
156
Brian Salomon6f1d36c2017-01-13 12:02:17 -0500157bool GrAtlasTextBlob::mustRegenerate(const GrTextUtils::Paint& paint,
Mike Reed80747ef2018-01-23 15:29:32 -0500158 const SkMaskFilterBase::BlurRec& blurRec,
joshualittfd5f6c12015-12-10 07:44:50 -0800159 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
160 // If we have LCD text then our canonical color will be set to transparent, in this case we have
161 // to regenerate the blob on any color change
162 // We use the grPaint to get any color filter effects
163 if (fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
Jim Van Verthbc2cdd12017-06-08 11:14:35 -0400164 fLuminanceColor != paint.luminanceColor()) {
joshualittfd5f6c12015-12-10 07:44:50 -0800165 return true;
166 }
167
joshualitt8e0ef292016-02-19 14:13:03 -0800168 if (fInitialViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) {
joshualittfd5f6c12015-12-10 07:44:50 -0800169 return true;
170 }
171
Brian Salomon5c6ac642017-12-19 11:09:32 -0500172 /** This could be relaxed for blobs with only distance field glyphs. */
joshualitt8e0ef292016-02-19 14:13:03 -0800173 if (fInitialViewMatrix.hasPerspective() && !fInitialViewMatrix.cheapEqualTo(viewMatrix)) {
joshualittfd5f6c12015-12-10 07:44:50 -0800174 return true;
175 }
176
177 // We only cache one masked version
178 if (fKey.fHasBlur &&
179 (fBlurRec.fSigma != blurRec.fSigma ||
180 fBlurRec.fStyle != blurRec.fStyle ||
181 fBlurRec.fQuality != blurRec.fQuality)) {
182 return true;
183 }
184
185 // Similarly, we only cache one version for each style
186 if (fKey.fStyle != SkPaint::kFill_Style &&
Brian Salomon6f1d36c2017-01-13 12:02:17 -0500187 (fStrokeInfo.fFrameWidth != paint.skPaint().getStrokeWidth() ||
188 fStrokeInfo.fMiterLimit != paint.skPaint().getStrokeMiter() ||
189 fStrokeInfo.fJoin != paint.skPaint().getStrokeJoin())) {
joshualittfd5f6c12015-12-10 07:44:50 -0800190 return true;
191 }
192
193 // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls
194 // for mixed blobs if this becomes an issue.
195 if (this->hasBitmap() && this->hasDistanceField()) {
196 // Identical viewmatrices and we can reuse in all cases
joshualitt8e0ef292016-02-19 14:13:03 -0800197 if (fInitialViewMatrix.cheapEqualTo(viewMatrix) && x == fInitialX && y == fInitialY) {
joshualittfd5f6c12015-12-10 07:44:50 -0800198 return false;
199 }
200 return true;
201 }
202
203 if (this->hasBitmap()) {
joshualitt8e0ef292016-02-19 14:13:03 -0800204 if (fInitialViewMatrix.getScaleX() != viewMatrix.getScaleX() ||
205 fInitialViewMatrix.getScaleY() != viewMatrix.getScaleY() ||
206 fInitialViewMatrix.getSkewX() != viewMatrix.getSkewX() ||
207 fInitialViewMatrix.getSkewY() != viewMatrix.getSkewY()) {
joshualittfd5f6c12015-12-10 07:44:50 -0800208 return true;
209 }
210
211 // We can update the positions in the cachedtextblobs without regenerating the whole blob,
212 // but only for integer translations.
213 // This cool bit of math will determine the necessary translation to apply to the already
214 // generated vertex coordinates to move them to the correct position
215 SkScalar transX = viewMatrix.getTranslateX() +
joshualitt8e0ef292016-02-19 14:13:03 -0800216 viewMatrix.getScaleX() * (x - fInitialX) +
217 viewMatrix.getSkewX() * (y - fInitialY) -
218 fInitialViewMatrix.getTranslateX();
joshualittfd5f6c12015-12-10 07:44:50 -0800219 SkScalar transY = viewMatrix.getTranslateY() +
joshualitt8e0ef292016-02-19 14:13:03 -0800220 viewMatrix.getSkewY() * (x - fInitialX) +
221 viewMatrix.getScaleY() * (y - fInitialY) -
222 fInitialViewMatrix.getTranslateY();
223 if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY)) {
joshualittfd5f6c12015-12-10 07:44:50 -0800224 return true;
225 }
joshualittfd5f6c12015-12-10 07:44:50 -0800226 } else if (this->hasDistanceField()) {
227 // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different
228 // distance field being generated, so we have to regenerate in those cases
229 SkScalar newMaxScale = viewMatrix.getMaxScale();
joshualitt8e0ef292016-02-19 14:13:03 -0800230 SkScalar oldMaxScale = fInitialViewMatrix.getMaxScale();
joshualittfd5f6c12015-12-10 07:44:50 -0800231 SkScalar scaleAdjust = newMaxScale / oldMaxScale;
232 if (scaleAdjust < fMaxMinScale || scaleAdjust > fMinMaxScale) {
233 return true;
234 }
joshualittfd5f6c12015-12-10 07:44:50 -0800235 }
236
joshualittfd5f6c12015-12-10 07:44:50 -0800237 // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case
238 // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate
239 // the blob anyways at flush time, so no need to regenerate explicitly
240 return false;
241}
242
Brian Salomonf18b1d82017-10-27 11:30:49 -0400243inline std::unique_ptr<GrAtlasTextOp> GrAtlasTextBlob::makeOp(
Jim Van Verth56c37142017-10-31 14:44:25 -0400244 const Run::SubRunInfo& info, int glyphCount, uint16_t run, uint16_t subRun,
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400245 const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect,
246 const GrTextUtils::Paint& paint, const SkSurfaceProps& props,
Brian Salomonf18b1d82017-10-27 11:30:49 -0400247 const GrDistanceFieldAdjustTable* distanceAdjustTable, GrAtlasGlyphCache* cache,
248 GrTextUtils::Target* target) {
joshualitt2e2202e2015-12-10 11:22:08 -0800249 GrMaskFormat format = info.maskFormat();
joshualitt2e2202e2015-12-10 11:22:08 -0800250
Brian Salomon44acb5b2017-07-18 19:59:24 -0400251 GrPaint grPaint;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400252 target->makeGrPaint(info.maskFormat(), paint, viewMatrix, &grPaint);
Brian Salomonf8334782017-01-03 09:42:58 -0500253 std::unique_ptr<GrAtlasTextOp> op;
joshualitt2e2202e2015-12-10 11:22:08 -0800254 if (info.drawAsDistanceFields()) {
joshualitt2e2202e2015-12-10 11:22:08 -0800255 bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
Brian Salomon44acb5b2017-07-18 19:59:24 -0400256 op = GrAtlasTextOp::MakeDistanceField(
257 std::move(grPaint), glyphCount, cache, distanceAdjustTable,
Brian Salomonf18b1d82017-10-27 11:30:49 -0400258 target->colorSpaceInfo().isGammaCorrect(), paint.luminanceColor(),
Brian Salomonf3569f02017-10-24 12:52:33 -0400259 info.hasUseLCDText(), useBGR, info.isAntiAliased());
joshualitt2e2202e2015-12-10 11:22:08 -0800260 } else {
Brian Salomon44acb5b2017-07-18 19:59:24 -0400261 op = GrAtlasTextOp::MakeBitmap(std::move(grPaint), format, glyphCount, cache);
joshualitt2e2202e2015-12-10 11:22:08 -0800262 }
Brian Salomon09d994e2016-12-21 11:14:46 -0500263 GrAtlasTextOp::Geometry& geometry = op->geometry();
joshualitt8e0ef292016-02-19 14:13:03 -0800264 geometry.fViewMatrix = viewMatrix;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400265 geometry.fClipRect = clipRect;
joshualitt2e2202e2015-12-10 11:22:08 -0800266 geometry.fBlob = SkRef(this);
267 geometry.fRun = run;
268 geometry.fSubRun = subRun;
Brian Salomon6f1d36c2017-01-13 12:02:17 -0500269 geometry.fColor =
Brian Osmanec8f8b02017-05-11 10:57:37 -0400270 info.maskFormat() == kARGB_GrMaskFormat ? GrColor_WHITE : paint.filteredPremulColor();
joshualitt8e0ef292016-02-19 14:13:03 -0800271 geometry.fX = x;
272 geometry.fY = y;
Brian Salomon09d994e2016-12-21 11:14:46 -0500273 op->init();
Brian Salomonf18b1d82017-10-27 11:30:49 -0400274 return op;
joshualitt2e2202e2015-12-10 11:22:08 -0800275}
276
joshualitt8e0ef292016-02-19 14:13:03 -0800277static void calculate_translation(bool applyVM,
278 const SkMatrix& newViewMatrix, SkScalar newX, SkScalar newY,
279 const SkMatrix& currentViewMatrix, SkScalar currentX,
280 SkScalar currentY, SkScalar* transX, SkScalar* transY) {
281 if (applyVM) {
282 *transX = newViewMatrix.getTranslateX() +
283 newViewMatrix.getScaleX() * (newX - currentX) +
284 newViewMatrix.getSkewX() * (newY - currentY) -
285 currentViewMatrix.getTranslateX();
286
287 *transY = newViewMatrix.getTranslateY() +
288 newViewMatrix.getSkewY() * (newX - currentX) +
289 newViewMatrix.getScaleY() * (newY - currentY) -
290 currentViewMatrix.getTranslateY();
291 } else {
292 *transX = newX - currentX;
293 *transY = newY - currentY;
294 }
295}
296
Jim Van Verth2fb7c8a2018-02-06 11:14:20 -0500297void GrAtlasTextBlob::flush(GrAtlasGlyphCache* atlasGlyphCache, GrTextUtils::Target* target,
298 const SkSurfaceProps& props,
299 const GrDistanceFieldAdjustTable* distanceAdjustTable,
300 const GrTextUtils::Paint& paint, const GrClip& clip,
301 const SkMatrix& viewMatrix, const SkIRect& clipBounds,
302 SkScalar x, SkScalar y) {
303
304 // GrAtlasTextBlob::makeOp only takes uint16_t values for run and subRun indices.
305 // Encountering something larger than this is highly unlikely, so we'll just not draw it.
306 int lastRun = SkTMin(fRunCount, (1 << 16)) - 1;
307 for (int runIndex = 0; runIndex <= lastRun; runIndex++) {
308 Run& run = fRuns[runIndex];
309
310 // first flush each subrun
311 int lastSubRun = SkTMin(run.fSubRunInfo.count(), 1 << 16) - 1;
312 for (int subRun = 0; subRun <= lastSubRun; subRun++) {
313 const Run::SubRunInfo& info = run.fSubRunInfo[subRun];
314 int glyphCount = info.glyphCount();
315 if (0 == glyphCount) {
316 continue;
317 }
318
319 bool skipClip = false;
320 bool submitOp = true;
321 SkIRect clipRect = SkIRect::MakeEmpty();
322 SkRect rtBounds = SkRect::MakeWH(target->width(), target->height());
323 SkRRect clipRRect;
324 GrAA aa;
325 // We can clip geometrically if we're not using SDFs,
326 // and we have an axis-aligned rectangular non-AA clip
327 if (!info.drawAsDistanceFields() && clip.isRRect(rtBounds, &clipRRect, &aa) &&
328 clipRRect.isRect() && GrAA::kNo == aa) {
329 skipClip = true;
330 // We only need to do clipping work if the subrun isn't contained by the clip
331 SkRect subRunBounds;
332 this->computeSubRunBounds(&subRunBounds, runIndex, subRun, viewMatrix, x, y);
333 if (!clipRRect.getBounds().contains(subRunBounds)) {
334 // If the subrun is completely outside, don't add an op for it
335 if (!clipRRect.getBounds().intersects(subRunBounds)) {
336 submitOp = false;
337 }
338 else {
339 clipRRect.getBounds().round(&clipRect);
340 }
341 }
342 }
343
344 if (submitOp) {
345 auto op = this->makeOp(info, glyphCount, runIndex, subRun, viewMatrix, x, y,
346 clipRect, std::move(paint), props, distanceAdjustTable,
347 atlasGlyphCache, target);
348 if (op) {
349 if (skipClip) {
350 target->addDrawOp(GrNoClip(), std::move(op));
351 }
352 else {
353 target->addDrawOp(clip, std::move(op));
354 }
355 }
356 }
joshualitt2e2202e2015-12-10 11:22:08 -0800357 }
joshualitt2e2202e2015-12-10 11:22:08 -0800358
Jim Van Verth2fb7c8a2018-02-06 11:14:20 -0500359 // now flush any path glyphs
360 SkScalar transX, transY;
361 for (int i = 0; i < run.fPathGlyphs.count(); i++) {
362 GrAtlasTextBlob::Run::PathGlyph& pathGlyph = run.fPathGlyphs[i];
363 calculate_translation(pathGlyph.fPreTransformed, viewMatrix, x, y,
364 fInitialViewMatrix, fInitialX, fInitialY, &transX, &transY);
365 const SkMatrix& ctm = pathGlyph.fPreTransformed ? SkMatrix::I() : viewMatrix;
366 SkMatrix pathMatrix;
367 pathMatrix.setScale(pathGlyph.fScale, pathGlyph.fScale);
368 pathMatrix.postTranslate(pathGlyph.fX + transX, pathGlyph.fY + transY);
369 target->drawPath(clip, pathGlyph.fPath, paint, ctm, &pathMatrix, clipBounds);
joshualitt2e2202e2015-12-10 11:22:08 -0800370 }
joshualitt2e2202e2015-12-10 11:22:08 -0800371 }
joshualitt2e2202e2015-12-10 11:22:08 -0800372}
373
Brian Salomon44acb5b2017-07-18 19:59:24 -0400374std::unique_ptr<GrDrawOp> GrAtlasTextBlob::test_makeOp(
Jim Van Verth56c37142017-10-31 14:44:25 -0400375 int glyphCount, uint16_t run, uint16_t subRun, const SkMatrix& viewMatrix,
376 SkScalar x, SkScalar y, const GrTextUtils::Paint& paint, const SkSurfaceProps& props,
Brian Salomon44acb5b2017-07-18 19:59:24 -0400377 const GrDistanceFieldAdjustTable* distanceAdjustTable, GrAtlasGlyphCache* cache,
Brian Salomonf18b1d82017-10-27 11:30:49 -0400378 GrTextUtils::Target* target) {
joshualitt7481e752016-01-22 06:08:48 -0800379 const GrAtlasTextBlob::Run::SubRunInfo& info = fRuns[run].fSubRunInfo[subRun];
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400380 SkIRect emptyRect = SkIRect::MakeEmpty();
Brian Salomonf18b1d82017-10-27 11:30:49 -0400381 return this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, emptyRect, paint, props,
382 distanceAdjustTable, cache, target);
joshualitt323c2eb2016-01-20 06:48:47 -0800383}
joshualitt2e2202e2015-12-10 11:22:08 -0800384
joshualitt259fbf12015-07-21 11:39:34 -0700385void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) {
joshualitt2f2ee832016-02-10 08:52:24 -0800386 SkASSERT_RELEASE(l.fSize == r.fSize);
387 SkASSERT_RELEASE(l.fPool == r.fPool);
joshualitt259fbf12015-07-21 11:39:34 -0700388
joshualitt2f2ee832016-02-10 08:52:24 -0800389 SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
390 SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
391 SkASSERT_RELEASE(l.fBlurRec.fQuality == r.fBlurRec.fQuality);
joshualitt259fbf12015-07-21 11:39:34 -0700392
joshualitt2f2ee832016-02-10 08:52:24 -0800393 SkASSERT_RELEASE(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth);
394 SkASSERT_RELEASE(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit);
395 SkASSERT_RELEASE(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin);
joshualitt259fbf12015-07-21 11:39:34 -0700396
joshualitt2f2ee832016-02-10 08:52:24 -0800397 SkASSERT_RELEASE(l.fKey == r.fKey);
joshualitt2f2ee832016-02-10 08:52:24 -0800398 //SkASSERT_RELEASE(l.fPaintColor == r.fPaintColor); // Colors might not actually be identical
399 SkASSERT_RELEASE(l.fMaxMinScale == r.fMaxMinScale);
400 SkASSERT_RELEASE(l.fMinMaxScale == r.fMinMaxScale);
401 SkASSERT_RELEASE(l.fTextType == r.fTextType);
joshualitt259fbf12015-07-21 11:39:34 -0700402
joshualitt2f2ee832016-02-10 08:52:24 -0800403 SkASSERT_RELEASE(l.fRunCount == r.fRunCount);
joshualitt259fbf12015-07-21 11:39:34 -0700404 for (int i = 0; i < l.fRunCount; i++) {
405 const Run& lRun = l.fRuns[i];
406 const Run& rRun = r.fRuns[i];
407
joshualitt259fbf12015-07-21 11:39:34 -0700408 if (lRun.fTypeface.get()) {
joshualitt2f2ee832016-02-10 08:52:24 -0800409 SkASSERT_RELEASE(rRun.fTypeface.get());
Hal Canary144caf52016-11-07 17:57:18 -0500410 SkASSERT_RELEASE(SkTypeface::Equal(lRun.fTypeface.get(), rRun.fTypeface.get()));
joshualitt259fbf12015-07-21 11:39:34 -0700411 } else {
joshualitt2f2ee832016-02-10 08:52:24 -0800412 SkASSERT_RELEASE(!rRun.fTypeface.get());
joshualitt259fbf12015-07-21 11:39:34 -0700413 }
414
joshualitt259fbf12015-07-21 11:39:34 -0700415
joshualitt2f2ee832016-02-10 08:52:24 -0800416 SkASSERT_RELEASE(lRun.fDescriptor.getDesc());
417 SkASSERT_RELEASE(rRun.fDescriptor.getDesc());
bsalomonc5d07fa2016-05-17 10:17:45 -0700418 SkASSERT_RELEASE(*lRun.fDescriptor.getDesc() == *rRun.fDescriptor.getDesc());
joshualitt259fbf12015-07-21 11:39:34 -0700419
420 if (lRun.fOverrideDescriptor.get()) {
joshualitt2f2ee832016-02-10 08:52:24 -0800421 SkASSERT_RELEASE(lRun.fOverrideDescriptor->getDesc());
422 SkASSERT_RELEASE(rRun.fOverrideDescriptor.get() && rRun.fOverrideDescriptor->getDesc());
bsalomonc5d07fa2016-05-17 10:17:45 -0700423 SkASSERT_RELEASE(*lRun.fOverrideDescriptor->getDesc() ==
424 *rRun.fOverrideDescriptor->getDesc());
joshualitt259fbf12015-07-21 11:39:34 -0700425 } else {
joshualitt2f2ee832016-02-10 08:52:24 -0800426 SkASSERT_RELEASE(!rRun.fOverrideDescriptor.get());
joshualitt259fbf12015-07-21 11:39:34 -0700427 }
428
429 // color can be changed
430 //SkASSERT(lRun.fColor == rRun.fColor);
joshualitt2f2ee832016-02-10 08:52:24 -0800431 SkASSERT_RELEASE(lRun.fInitialized == rRun.fInitialized);
joshualitt259fbf12015-07-21 11:39:34 -0700432
joshualitt2f2ee832016-02-10 08:52:24 -0800433 SkASSERT_RELEASE(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count());
joshualitt259fbf12015-07-21 11:39:34 -0700434 for(int j = 0; j < lRun.fSubRunInfo.count(); j++) {
435 const Run::SubRunInfo& lSubRun = lRun.fSubRunInfo[j];
436 const Run::SubRunInfo& rSubRun = rRun.fSubRunInfo[j];
437
joshualitt2f2ee832016-02-10 08:52:24 -0800438 // TODO we can do this check, but we have to apply the VM to the old vertex bounds
439 //SkASSERT_RELEASE(lSubRun.vertexBounds() == rSubRun.vertexBounds());
joshualitt259fbf12015-07-21 11:39:34 -0700440
joshualitt2f2ee832016-02-10 08:52:24 -0800441 if (lSubRun.strike()) {
442 SkASSERT_RELEASE(rSubRun.strike());
Brian Salomonf856fd12016-12-16 14:24:34 -0500443 SkASSERT_RELEASE(GrAtlasTextStrike::GetKey(*lSubRun.strike()) ==
444 GrAtlasTextStrike::GetKey(*rSubRun.strike()));
joshualitt2f2ee832016-02-10 08:52:24 -0800445
446 } else {
447 SkASSERT_RELEASE(!rSubRun.strike());
448 }
449
450 SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIndex());
451 SkASSERT_RELEASE(lSubRun.vertexEndIndex() == rSubRun.vertexEndIndex());
452 SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartIndex());
453 SkASSERT_RELEASE(lSubRun.glyphEndIndex() == rSubRun.glyphEndIndex());
454 SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat());
455 SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDistanceFields());
456 SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText());
joshualitt259fbf12015-07-21 11:39:34 -0700457 }
Jim Van Verth2fb7c8a2018-02-06 11:14:20 -0500458
459 SkASSERT_RELEASE(lRun.fPathGlyphs.count() == rRun.fPathGlyphs.count());
460 for (int i = 0; i < lRun.fPathGlyphs.count(); i++) {
461 const Run::PathGlyph& lPathGlyph = lRun.fPathGlyphs[i];
462 const Run::PathGlyph& rPathGlyph = rRun.fPathGlyphs[i];
463
464 SkASSERT_RELEASE(lPathGlyph.fPath == rPathGlyph.fPath);
465 // We can't assert that these have the same translations
466 }
joshualitt259fbf12015-07-21 11:39:34 -0700467 }
468}
joshualitt8e0ef292016-02-19 14:13:03 -0800469
470void GrAtlasTextBlob::Run::SubRunInfo::computeTranslation(const SkMatrix& viewMatrix,
471 SkScalar x, SkScalar y, SkScalar* transX,
472 SkScalar* transY) {
473 calculate_translation(!this->drawAsDistanceFields(), viewMatrix, x, y,
474 fCurrentViewMatrix, fX, fY, transX, transY);
475 fCurrentViewMatrix = viewMatrix;
476 fX = x;
477 fY = y;
478}