blob: e80576187be60169b491039462840c5b0b66b672 [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"
Jim Van Verth54d9c882018-02-08 16:14:48 -050018#include "SkTextToPathIter.h"
Brian Salomon89527432016-12-16 09:52:16 -050019#include "ops/GrAtlasTextOp.h"
joshualitt2e2202e2015-12-10 11:22:08 -080020
Florin Malitac337c9e2017-03-10 18:02:29 +000021sk_sp<GrAtlasTextBlob> GrAtlasTextBlob::Make(GrMemoryPool* pool, int glyphCount, int runCount) {
joshualitt92303772016-02-10 11:55:52 -080022 // We allocate size for the GrAtlasTextBlob itself, plus size for the vertices array,
23 // and size for the glyphIds array.
24 size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
25 size_t size = sizeof(GrAtlasTextBlob) +
26 verticesCount +
27 glyphCount * sizeof(GrGlyph**) +
28 sizeof(GrAtlasTextBlob::Run) * runCount;
29
30 void* allocation = pool->allocate(size);
31 if (CACHE_SANITY_CHECK) {
32 sk_bzero(allocation, size);
33 }
34
Florin Malitac337c9e2017-03-10 18:02:29 +000035 sk_sp<GrAtlasTextBlob> cacheBlob(new (allocation) GrAtlasTextBlob);
joshualitt92303772016-02-10 11:55:52 -080036 cacheBlob->fSize = size;
37
38 // setup offsets for vertices / glyphs
Brian Salomon18923f92017-11-06 16:26:02 -050039 cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<char*>(cacheBlob.get());
joshualitt92303772016-02-10 11:55:52 -080040 cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + verticesCount);
41 cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyphs + glyphCount);
42
43 // Initialize runs
44 for (int i = 0; i < runCount; i++) {
45 new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run;
46 }
47 cacheBlob->fRunCount = runCount;
48 cacheBlob->fPool = pool;
49 return cacheBlob;
50}
51
joshualitte76b4bb32015-12-28 07:23:58 -080052SkGlyphCache* GrAtlasTextBlob::setupCache(int runIndex,
53 const SkSurfaceProps& props,
Herb Derbyd8327a82018-01-22 14:39:27 -050054 SkScalerContextFlags scalerContextFlags,
joshualitte76b4bb32015-12-28 07:23:58 -080055 const SkPaint& skPaint,
bungemanf6d1e602016-02-22 13:20:28 -080056 const SkMatrix* viewMatrix) {
joshualitte76b4bb32015-12-28 07:23:58 -080057 GrAtlasTextBlob::Run* run = &fRuns[runIndex];
58
59 // if we have an override descriptor for the run, then we should use that
60 SkAutoDescriptor* desc = run->fOverrideDescriptor.get() ? run->fOverrideDescriptor.get() :
61 &run->fDescriptor;
bsalomon8b6fa5e2016-05-19 16:23:47 -070062 SkScalerContextEffects effects;
Herb Derby980a48d2018-01-23 13:39:21 -050063 SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
64 skPaint, &props, scalerContextFlags, viewMatrix, desc, &effects);
joshualitte76b4bb32015-12-28 07:23:58 -080065 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface()));
bsalomon8b6fa5e2016-05-19 16:23:47 -070066 run->fPathEffect = sk_ref_sp(effects.fPathEffect);
bsalomon8b6fa5e2016-05-19 16:23:47 -070067 run->fMaskFilter = sk_ref_sp(effects.fMaskFilter);
Hal Canary144caf52016-11-07 17:57:18 -050068 return SkGlyphCache::DetachCache(run->fTypeface.get(), effects, desc->getDesc());
joshualitte76b4bb32015-12-28 07:23:58 -080069}
70
joshualittf528e0d2015-12-09 06:42:52 -080071void GrAtlasTextBlob::appendGlyph(int runIndex,
72 const SkRect& positions,
73 GrColor color,
Brian Salomonf856fd12016-12-16 14:24:34 -050074 GrAtlasTextStrike* strike,
joshualitta06e6ab2015-12-10 08:54:41 -080075 GrGlyph* glyph,
bsalomonc2878e22016-05-17 13:18:03 -070076 SkGlyphCache* cache, const SkGlyph& skGlyph,
Jim Van Verth54d9c882018-02-08 16:14:48 -050077 SkScalar x, SkScalar y, SkScalar scale, bool preTransformed) {
Lee Salzman26d3f212017-01-27 14:31:10 -050078 if (positions.isEmpty()) {
79 return;
80 }
joshualitta06e6ab2015-12-10 08:54:41 -080081
82 // If the glyph is too large we fall back to paths
83 if (glyph->fTooLargeForAtlas) {
Jim Van Verth54d9c882018-02-08 16:14:48 -050084 if (nullptr == glyph->fPath) {
85 const SkPath* glyphPath = cache->findPath(skGlyph);
86 if (!glyphPath) {
87 return;
88 }
89
90 glyph->fPath = new SkPath(*glyphPath);
91 }
92 this->appendPathGlyph(runIndex, *glyph->fPath, x, y, scale, preTransformed);
joshualitta06e6ab2015-12-10 08:54:41 -080093 return;
94 }
95
joshualittf528e0d2015-12-09 06:42:52 -080096 Run& run = fRuns[runIndex];
97 GrMaskFormat format = glyph->fMaskFormat;
98
99 Run::SubRunInfo* subRun = &run.fSubRunInfo.back();
100 if (run.fInitialized && subRun->maskFormat() != format) {
101 subRun = &run.push_back();
102 subRun->setStrike(strike);
103 } else if (!run.fInitialized) {
104 subRun->setStrike(strike);
105 }
106
107 run.fInitialized = true;
108
Brian Salomon5c6ac642017-12-19 11:09:32 -0500109 bool hasW = subRun->hasWCoord();
110 // DF glyphs drawn in perspective must always have a w coord.
111 SkASSERT(hasW || !subRun->drawAsDistanceFields() || !fInitialViewMatrix.hasPerspective());
112 // Non-DF glyphs should never have a w coord.
113 SkASSERT(!hasW || subRun->drawAsDistanceFields());
114
115 size_t vertexStride = GetVertexStride(format, hasW);
joshualittf528e0d2015-12-09 06:42:52 -0800116
117 subRun->setMaskFormat(format);
118
joshualitt7481e752016-01-22 06:08:48 -0800119 subRun->joinGlyphBounds(positions);
joshualittf9e658b2015-12-09 09:26:44 -0800120 subRun->setColor(color);
joshualitt18b072d2015-12-07 12:26:12 -0800121
122 intptr_t vertex = reinterpret_cast<intptr_t>(this->fVertices + subRun->vertexEndIndex());
123
Brian Salomon5c6ac642017-12-19 11:09:32 -0500124 // We always write the third position component used by SDFs. If it is unused it gets
125 // overwritten. Similarly, we always write the color and the blob will later overwrite it
126 // with texture coords if it is unused.
127 size_t colorOffset = hasW ? sizeof(SkPoint3) : sizeof(SkPoint);
128 // V0
129 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fLeft, positions.fTop, 1.f};
130 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
131 vertex += vertexStride;
joshualitt18b072d2015-12-07 12:26:12 -0800132
Brian Salomon5c6ac642017-12-19 11:09:32 -0500133 // V1
134 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fLeft, positions.fBottom, 1.f};
135 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
136 vertex += vertexStride;
joshualitt18b072d2015-12-07 12:26:12 -0800137
Brian Salomon5c6ac642017-12-19 11:09:32 -0500138 // V2
139 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fRight, positions.fTop, 1.f};
140 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
141 vertex += vertexStride;
joshualitt18b072d2015-12-07 12:26:12 -0800142
Brian Salomon5c6ac642017-12-19 11:09:32 -0500143 // V3
144 *reinterpret_cast<SkPoint3*>(vertex) = {positions.fRight, positions.fBottom, 1.f};
145 *reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
joshualitt18b072d2015-12-07 12:26:12 -0800146
joshualitt18b072d2015-12-07 12:26:12 -0800147 subRun->appendVertices(vertexStride);
148 fGlyphs[subRun->glyphEndIndex()] = glyph;
149 subRun->glyphAppended();
150}
151
Jim Van Verth54d9c882018-02-08 16:14:48 -0500152void GrAtlasTextBlob::appendPathGlyph(int runIndex, const SkPath& path, SkScalar x, SkScalar y,
153 SkScalar scale, bool preTransformed) {
154 Run& run = fRuns[runIndex];
155 run.fPathGlyphs.push_back(GrAtlasTextBlob::Run::PathGlyph(path, x, y, scale, preTransformed));
joshualitta06e6ab2015-12-10 08:54:41 -0800156}
157
Brian Salomon6f1d36c2017-01-13 12:02:17 -0500158bool GrAtlasTextBlob::mustRegenerate(const GrTextUtils::Paint& paint,
Mike Reed80747ef2018-01-23 15:29:32 -0500159 const SkMaskFilterBase::BlurRec& blurRec,
joshualittfd5f6c12015-12-10 07:44:50 -0800160 const SkMatrix& viewMatrix, SkScalar x, SkScalar y) {
161 // If we have LCD text then our canonical color will be set to transparent, in this case we have
162 // to regenerate the blob on any color change
163 // We use the grPaint to get any color filter effects
164 if (fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
Jim Van Verthbc2cdd12017-06-08 11:14:35 -0400165 fLuminanceColor != paint.luminanceColor()) {
joshualittfd5f6c12015-12-10 07:44:50 -0800166 return true;
167 }
168
joshualitt8e0ef292016-02-19 14:13:03 -0800169 if (fInitialViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) {
joshualittfd5f6c12015-12-10 07:44:50 -0800170 return true;
171 }
172
Brian Salomon5c6ac642017-12-19 11:09:32 -0500173 /** This could be relaxed for blobs with only distance field glyphs. */
joshualitt8e0ef292016-02-19 14:13:03 -0800174 if (fInitialViewMatrix.hasPerspective() && !fInitialViewMatrix.cheapEqualTo(viewMatrix)) {
joshualittfd5f6c12015-12-10 07:44:50 -0800175 return true;
176 }
177
178 // We only cache one masked version
179 if (fKey.fHasBlur &&
180 (fBlurRec.fSigma != blurRec.fSigma ||
181 fBlurRec.fStyle != blurRec.fStyle ||
182 fBlurRec.fQuality != blurRec.fQuality)) {
183 return true;
184 }
185
186 // Similarly, we only cache one version for each style
187 if (fKey.fStyle != SkPaint::kFill_Style &&
Brian Salomon6f1d36c2017-01-13 12:02:17 -0500188 (fStrokeInfo.fFrameWidth != paint.skPaint().getStrokeWidth() ||
189 fStrokeInfo.fMiterLimit != paint.skPaint().getStrokeMiter() ||
190 fStrokeInfo.fJoin != paint.skPaint().getStrokeJoin())) {
joshualittfd5f6c12015-12-10 07:44:50 -0800191 return true;
192 }
193
194 // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls
195 // for mixed blobs if this becomes an issue.
196 if (this->hasBitmap() && this->hasDistanceField()) {
197 // Identical viewmatrices and we can reuse in all cases
joshualitt8e0ef292016-02-19 14:13:03 -0800198 if (fInitialViewMatrix.cheapEqualTo(viewMatrix) && x == fInitialX && y == fInitialY) {
joshualittfd5f6c12015-12-10 07:44:50 -0800199 return false;
200 }
201 return true;
202 }
203
204 if (this->hasBitmap()) {
joshualitt8e0ef292016-02-19 14:13:03 -0800205 if (fInitialViewMatrix.getScaleX() != viewMatrix.getScaleX() ||
206 fInitialViewMatrix.getScaleY() != viewMatrix.getScaleY() ||
207 fInitialViewMatrix.getSkewX() != viewMatrix.getSkewX() ||
208 fInitialViewMatrix.getSkewY() != viewMatrix.getSkewY()) {
joshualittfd5f6c12015-12-10 07:44:50 -0800209 return true;
210 }
211
212 // We can update the positions in the cachedtextblobs without regenerating the whole blob,
213 // but only for integer translations.
214 // This cool bit of math will determine the necessary translation to apply to the already
215 // generated vertex coordinates to move them to the correct position
216 SkScalar transX = viewMatrix.getTranslateX() +
joshualitt8e0ef292016-02-19 14:13:03 -0800217 viewMatrix.getScaleX() * (x - fInitialX) +
218 viewMatrix.getSkewX() * (y - fInitialY) -
219 fInitialViewMatrix.getTranslateX();
joshualittfd5f6c12015-12-10 07:44:50 -0800220 SkScalar transY = viewMatrix.getTranslateY() +
joshualitt8e0ef292016-02-19 14:13:03 -0800221 viewMatrix.getSkewY() * (x - fInitialX) +
222 viewMatrix.getScaleY() * (y - fInitialY) -
223 fInitialViewMatrix.getTranslateY();
224 if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY)) {
joshualittfd5f6c12015-12-10 07:44:50 -0800225 return true;
226 }
joshualittfd5f6c12015-12-10 07:44:50 -0800227 } else if (this->hasDistanceField()) {
228 // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different
229 // distance field being generated, so we have to regenerate in those cases
230 SkScalar newMaxScale = viewMatrix.getMaxScale();
joshualitt8e0ef292016-02-19 14:13:03 -0800231 SkScalar oldMaxScale = fInitialViewMatrix.getMaxScale();
joshualittfd5f6c12015-12-10 07:44:50 -0800232 SkScalar scaleAdjust = newMaxScale / oldMaxScale;
233 if (scaleAdjust < fMaxMinScale || scaleAdjust > fMinMaxScale) {
234 return true;
235 }
joshualittfd5f6c12015-12-10 07:44:50 -0800236 }
237
joshualittfd5f6c12015-12-10 07:44:50 -0800238 // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case
239 // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate
240 // the blob anyways at flush time, so no need to regenerate explicitly
241 return false;
242}
243
Brian Salomonf18b1d82017-10-27 11:30:49 -0400244inline std::unique_ptr<GrAtlasTextOp> GrAtlasTextBlob::makeOp(
Jim Van Verth56c37142017-10-31 14:44:25 -0400245 const Run::SubRunInfo& info, int glyphCount, uint16_t run, uint16_t subRun,
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400246 const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect,
247 const GrTextUtils::Paint& paint, const SkSurfaceProps& props,
Brian Salomonf18b1d82017-10-27 11:30:49 -0400248 const GrDistanceFieldAdjustTable* distanceAdjustTable, GrAtlasGlyphCache* cache,
249 GrTextUtils::Target* target) {
joshualitt2e2202e2015-12-10 11:22:08 -0800250 GrMaskFormat format = info.maskFormat();
joshualitt2e2202e2015-12-10 11:22:08 -0800251
Brian Salomon44acb5b2017-07-18 19:59:24 -0400252 GrPaint grPaint;
Brian Salomonf18b1d82017-10-27 11:30:49 -0400253 target->makeGrPaint(info.maskFormat(), paint, viewMatrix, &grPaint);
Brian Salomonf8334782017-01-03 09:42:58 -0500254 std::unique_ptr<GrAtlasTextOp> op;
joshualitt2e2202e2015-12-10 11:22:08 -0800255 if (info.drawAsDistanceFields()) {
joshualitt2e2202e2015-12-10 11:22:08 -0800256 bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
Brian Salomon44acb5b2017-07-18 19:59:24 -0400257 op = GrAtlasTextOp::MakeDistanceField(
258 std::move(grPaint), glyphCount, cache, distanceAdjustTable,
Brian Salomonf18b1d82017-10-27 11:30:49 -0400259 target->colorSpaceInfo().isGammaCorrect(), paint.luminanceColor(),
Brian Salomonf3569f02017-10-24 12:52:33 -0400260 info.hasUseLCDText(), useBGR, info.isAntiAliased());
joshualitt2e2202e2015-12-10 11:22:08 -0800261 } else {
Brian Salomon44acb5b2017-07-18 19:59:24 -0400262 op = GrAtlasTextOp::MakeBitmap(std::move(grPaint), format, glyphCount, cache);
joshualitt2e2202e2015-12-10 11:22:08 -0800263 }
Brian Salomon09d994e2016-12-21 11:14:46 -0500264 GrAtlasTextOp::Geometry& geometry = op->geometry();
joshualitt8e0ef292016-02-19 14:13:03 -0800265 geometry.fViewMatrix = viewMatrix;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400266 geometry.fClipRect = clipRect;
joshualitt2e2202e2015-12-10 11:22:08 -0800267 geometry.fBlob = SkRef(this);
268 geometry.fRun = run;
269 geometry.fSubRun = subRun;
Brian Salomon6f1d36c2017-01-13 12:02:17 -0500270 geometry.fColor =
Brian Osmanec8f8b02017-05-11 10:57:37 -0400271 info.maskFormat() == kARGB_GrMaskFormat ? GrColor_WHITE : paint.filteredPremulColor();
joshualitt8e0ef292016-02-19 14:13:03 -0800272 geometry.fX = x;
273 geometry.fY = y;
Brian Salomon09d994e2016-12-21 11:14:46 -0500274 op->init();
Brian Salomonf18b1d82017-10-27 11:30:49 -0400275 return op;
joshualitt2e2202e2015-12-10 11:22:08 -0800276}
277
joshualitt8e0ef292016-02-19 14:13:03 -0800278static void calculate_translation(bool applyVM,
279 const SkMatrix& newViewMatrix, SkScalar newX, SkScalar newY,
280 const SkMatrix& currentViewMatrix, SkScalar currentX,
281 SkScalar currentY, SkScalar* transX, SkScalar* transY) {
282 if (applyVM) {
283 *transX = newViewMatrix.getTranslateX() +
284 newViewMatrix.getScaleX() * (newX - currentX) +
285 newViewMatrix.getSkewX() * (newY - currentY) -
286 currentViewMatrix.getTranslateX();
287
288 *transY = newViewMatrix.getTranslateY() +
289 newViewMatrix.getSkewY() * (newX - currentX) +
290 newViewMatrix.getScaleY() * (newY - currentY) -
291 currentViewMatrix.getTranslateY();
292 } else {
293 *transX = newX - currentX;
294 *transY = newY - currentY;
295 }
296}
297
Jim Van Verth54d9c882018-02-08 16:14:48 -0500298void GrAtlasTextBlob::flush(GrAtlasGlyphCache* atlasGlyphCache, GrTextUtils::Target* target,
299 const SkSurfaceProps& props,
300 const GrDistanceFieldAdjustTable* distanceAdjustTable,
301 const GrTextUtils::Paint& paint, const GrClip& clip,
302 const SkMatrix& viewMatrix, const SkIRect& clipBounds,
303 SkScalar x, SkScalar y) {
304
305 // GrAtlasTextBlob::makeOp only takes uint16_t values for run and subRun indices.
306 // Encountering something larger than this is highly unlikely, so we'll just not draw it.
307 int lastRun = SkTMin(fRunCount, (1 << 16)) - 1;
308 GrTextUtils::RunPaint runPaint(&paint, nullptr, props);
309 for (int runIndex = 0; runIndex <= lastRun; runIndex++) {
310 Run& run = fRuns[runIndex];
311
312 // first flush any path glyphs
313 if (run.fPathGlyphs.count()) {
314 SkScalar transX, transY;
315 uint16_t paintFlags = run.fPaintFlags;
316 if (!runPaint.modifyForRun(
317 [paintFlags](SkPaint* p) {
318 p->setFlags((p->getFlags() & ~Run::kPaintFlagsMask) | paintFlags);
319 })) {
320 continue;
321 }
322 for (int i = 0; i < run.fPathGlyphs.count(); i++) {
323 GrAtlasTextBlob::Run::PathGlyph& pathGlyph = run.fPathGlyphs[i];
324 calculate_translation(pathGlyph.fPreTransformed, viewMatrix, x, y,
325 fInitialViewMatrix, fInitialX, fInitialY, &transX, &transY);
326 const SkMatrix& ctm = pathGlyph.fPreTransformed ? SkMatrix::I() : viewMatrix;
327 SkMatrix pathMatrix;
328 pathMatrix.setScale(pathGlyph.fScale, pathGlyph.fScale);
329 pathMatrix.postTranslate(pathGlyph.fX + transX, pathGlyph.fY + transY);
330 target->drawPath(clip, pathGlyph.fPath, runPaint, ctm, &pathMatrix, clipBounds);
331 }
joshualitt2e2202e2015-12-10 11:22:08 -0800332 }
joshualitt2e2202e2015-12-10 11:22:08 -0800333
Jim Van Verth54d9c882018-02-08 16:14:48 -0500334 // then flush each subrun, if any
335 if (!run.fInitialized) {
Jim Van Verth89737de2018-02-06 21:30:20 +0000336 continue;
337 }
Jim Van Verth54d9c882018-02-08 16:14:48 -0500338 int lastSubRun = SkTMin(run.fSubRunInfo.count(), 1 << 16) - 1;
339 for (int subRun = 0; subRun <= lastSubRun; subRun++) {
340 const Run::SubRunInfo& info = run.fSubRunInfo[subRun];
341 int glyphCount = info.glyphCount();
342 if (0 == glyphCount) {
343 continue;
344 }
345
346 bool skipClip = false;
347 bool submitOp = true;
348 SkIRect clipRect = SkIRect::MakeEmpty();
349 SkRect rtBounds = SkRect::MakeWH(target->width(), target->height());
350 SkRRect clipRRect;
351 GrAA aa;
352 // We can clip geometrically if we're not using SDFs,
353 // and we have an axis-aligned rectangular non-AA clip
354 if (!info.drawAsDistanceFields() && clip.isRRect(rtBounds, &clipRRect, &aa) &&
355 clipRRect.isRect() && GrAA::kNo == aa) {
356 skipClip = true;
357 // We only need to do clipping work if the subrun isn't contained by the clip
358 SkRect subRunBounds;
359 this->computeSubRunBounds(&subRunBounds, runIndex, subRun, viewMatrix, x, y);
360 if (!clipRRect.getBounds().contains(subRunBounds)) {
361 // If the subrun is completely outside, don't add an op for it
362 if (!clipRRect.getBounds().intersects(subRunBounds)) {
363 submitOp = false;
364 }
365 else {
366 clipRRect.getBounds().round(&clipRect);
367 }
368 }
369 }
370
371 if (submitOp) {
372 auto op = this->makeOp(info, glyphCount, runIndex, subRun, viewMatrix, x, y,
373 clipRect, std::move(paint), props, distanceAdjustTable,
374 atlasGlyphCache, target);
375 if (op) {
376 if (skipClip) {
377 target->addDrawOp(GrNoClip(), std::move(op));
378 }
379 else {
380 target->addDrawOp(clip, std::move(op));
381 }
382 }
383 }
384 }
385
Jim Van Verth89737de2018-02-06 21:30:20 +0000386 }
Jim Van Verth89737de2018-02-06 21:30:20 +0000387}
388
Brian Salomon44acb5b2017-07-18 19:59:24 -0400389std::unique_ptr<GrDrawOp> GrAtlasTextBlob::test_makeOp(
Jim Van Verth56c37142017-10-31 14:44:25 -0400390 int glyphCount, uint16_t run, uint16_t subRun, const SkMatrix& viewMatrix,
391 SkScalar x, SkScalar y, const GrTextUtils::Paint& paint, const SkSurfaceProps& props,
Brian Salomon44acb5b2017-07-18 19:59:24 -0400392 const GrDistanceFieldAdjustTable* distanceAdjustTable, GrAtlasGlyphCache* cache,
Brian Salomonf18b1d82017-10-27 11:30:49 -0400393 GrTextUtils::Target* target) {
joshualitt7481e752016-01-22 06:08:48 -0800394 const GrAtlasTextBlob::Run::SubRunInfo& info = fRuns[run].fSubRunInfo[subRun];
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400395 SkIRect emptyRect = SkIRect::MakeEmpty();
Brian Salomonf18b1d82017-10-27 11:30:49 -0400396 return this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, emptyRect, paint, props,
397 distanceAdjustTable, cache, target);
joshualitt323c2eb2016-01-20 06:48:47 -0800398}
joshualitt2e2202e2015-12-10 11:22:08 -0800399
joshualitt259fbf12015-07-21 11:39:34 -0700400void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) {
joshualitt2f2ee832016-02-10 08:52:24 -0800401 SkASSERT_RELEASE(l.fSize == r.fSize);
402 SkASSERT_RELEASE(l.fPool == r.fPool);
joshualitt259fbf12015-07-21 11:39:34 -0700403
joshualitt2f2ee832016-02-10 08:52:24 -0800404 SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
405 SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
406 SkASSERT_RELEASE(l.fBlurRec.fQuality == r.fBlurRec.fQuality);
joshualitt259fbf12015-07-21 11:39:34 -0700407
joshualitt2f2ee832016-02-10 08:52:24 -0800408 SkASSERT_RELEASE(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth);
409 SkASSERT_RELEASE(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit);
410 SkASSERT_RELEASE(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin);
joshualitt259fbf12015-07-21 11:39:34 -0700411
joshualitt2f2ee832016-02-10 08:52:24 -0800412 SkASSERT_RELEASE(l.fKey == r.fKey);
joshualitt2f2ee832016-02-10 08:52:24 -0800413 //SkASSERT_RELEASE(l.fPaintColor == r.fPaintColor); // Colors might not actually be identical
414 SkASSERT_RELEASE(l.fMaxMinScale == r.fMaxMinScale);
415 SkASSERT_RELEASE(l.fMinMaxScale == r.fMinMaxScale);
416 SkASSERT_RELEASE(l.fTextType == r.fTextType);
joshualitt259fbf12015-07-21 11:39:34 -0700417
joshualitt2f2ee832016-02-10 08:52:24 -0800418 SkASSERT_RELEASE(l.fRunCount == r.fRunCount);
joshualitt259fbf12015-07-21 11:39:34 -0700419 for (int i = 0; i < l.fRunCount; i++) {
420 const Run& lRun = l.fRuns[i];
421 const Run& rRun = r.fRuns[i];
422
joshualitt259fbf12015-07-21 11:39:34 -0700423 if (lRun.fTypeface.get()) {
joshualitt2f2ee832016-02-10 08:52:24 -0800424 SkASSERT_RELEASE(rRun.fTypeface.get());
Hal Canary144caf52016-11-07 17:57:18 -0500425 SkASSERT_RELEASE(SkTypeface::Equal(lRun.fTypeface.get(), rRun.fTypeface.get()));
joshualitt259fbf12015-07-21 11:39:34 -0700426 } else {
joshualitt2f2ee832016-02-10 08:52:24 -0800427 SkASSERT_RELEASE(!rRun.fTypeface.get());
joshualitt259fbf12015-07-21 11:39:34 -0700428 }
429
joshualitt259fbf12015-07-21 11:39:34 -0700430
joshualitt2f2ee832016-02-10 08:52:24 -0800431 SkASSERT_RELEASE(lRun.fDescriptor.getDesc());
432 SkASSERT_RELEASE(rRun.fDescriptor.getDesc());
bsalomonc5d07fa2016-05-17 10:17:45 -0700433 SkASSERT_RELEASE(*lRun.fDescriptor.getDesc() == *rRun.fDescriptor.getDesc());
joshualitt259fbf12015-07-21 11:39:34 -0700434
435 if (lRun.fOverrideDescriptor.get()) {
joshualitt2f2ee832016-02-10 08:52:24 -0800436 SkASSERT_RELEASE(lRun.fOverrideDescriptor->getDesc());
437 SkASSERT_RELEASE(rRun.fOverrideDescriptor.get() && rRun.fOverrideDescriptor->getDesc());
bsalomonc5d07fa2016-05-17 10:17:45 -0700438 SkASSERT_RELEASE(*lRun.fOverrideDescriptor->getDesc() ==
439 *rRun.fOverrideDescriptor->getDesc());
joshualitt259fbf12015-07-21 11:39:34 -0700440 } else {
joshualitt2f2ee832016-02-10 08:52:24 -0800441 SkASSERT_RELEASE(!rRun.fOverrideDescriptor.get());
joshualitt259fbf12015-07-21 11:39:34 -0700442 }
443
444 // color can be changed
445 //SkASSERT(lRun.fColor == rRun.fColor);
joshualitt2f2ee832016-02-10 08:52:24 -0800446 SkASSERT_RELEASE(lRun.fInitialized == rRun.fInitialized);
joshualitt259fbf12015-07-21 11:39:34 -0700447
joshualitt2f2ee832016-02-10 08:52:24 -0800448 SkASSERT_RELEASE(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count());
joshualitt259fbf12015-07-21 11:39:34 -0700449 for(int j = 0; j < lRun.fSubRunInfo.count(); j++) {
450 const Run::SubRunInfo& lSubRun = lRun.fSubRunInfo[j];
451 const Run::SubRunInfo& rSubRun = rRun.fSubRunInfo[j];
452
joshualitt2f2ee832016-02-10 08:52:24 -0800453 // TODO we can do this check, but we have to apply the VM to the old vertex bounds
454 //SkASSERT_RELEASE(lSubRun.vertexBounds() == rSubRun.vertexBounds());
joshualitt259fbf12015-07-21 11:39:34 -0700455
joshualitt2f2ee832016-02-10 08:52:24 -0800456 if (lSubRun.strike()) {
457 SkASSERT_RELEASE(rSubRun.strike());
Brian Salomonf856fd12016-12-16 14:24:34 -0500458 SkASSERT_RELEASE(GrAtlasTextStrike::GetKey(*lSubRun.strike()) ==
459 GrAtlasTextStrike::GetKey(*rSubRun.strike()));
joshualitt2f2ee832016-02-10 08:52:24 -0800460
461 } else {
462 SkASSERT_RELEASE(!rSubRun.strike());
463 }
464
465 SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIndex());
466 SkASSERT_RELEASE(lSubRun.vertexEndIndex() == rSubRun.vertexEndIndex());
467 SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartIndex());
468 SkASSERT_RELEASE(lSubRun.glyphEndIndex() == rSubRun.glyphEndIndex());
469 SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat());
470 SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDistanceFields());
471 SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText());
joshualitt259fbf12015-07-21 11:39:34 -0700472 }
Jim Van Verth54d9c882018-02-08 16:14:48 -0500473
474 SkASSERT_RELEASE(lRun.fPathGlyphs.count() == rRun.fPathGlyphs.count());
475 for (int i = 0; i < lRun.fPathGlyphs.count(); i++) {
476 const Run::PathGlyph& lPathGlyph = lRun.fPathGlyphs[i];
477 const Run::PathGlyph& rPathGlyph = rRun.fPathGlyphs[i];
478
479 SkASSERT_RELEASE(lPathGlyph.fPath == rPathGlyph.fPath);
480 // We can't assert that these have the same translations
481 }
joshualitt259fbf12015-07-21 11:39:34 -0700482 }
483}
joshualitt8e0ef292016-02-19 14:13:03 -0800484
485void GrAtlasTextBlob::Run::SubRunInfo::computeTranslation(const SkMatrix& viewMatrix,
486 SkScalar x, SkScalar y, SkScalar* transX,
487 SkScalar* transY) {
488 calculate_translation(!this->drawAsDistanceFields(), viewMatrix, x, y,
489 fCurrentViewMatrix, fX, fY, transX, transY);
490 fCurrentViewMatrix = viewMatrix;
491 fX = x;
492 fY = y;
493}