joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 1 | /* |
| 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" |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 9 | #include "GrBlurUtils.h" |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 10 | #include "GrClip.h" |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 11 | #include "GrContext.h" |
joshualitt | 0a42e68 | 2015-12-10 13:20:58 -0800 | [diff] [blame] | 12 | #include "GrTextUtils.h" |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 13 | #include "SkColorFilter.h" |
| 14 | #include "SkDrawFilter.h" |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 15 | #include "SkGlyphCache.h" |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 16 | #include "SkTextBlobRunIterator.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 17 | #include "ops/GrAtlasTextOp.h" |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 18 | |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 19 | sk_sp<GrAtlasTextBlob> GrAtlasTextBlob::Make(GrMemoryPool* pool, int glyphCount, int runCount) { |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 20 | // We allocate size for the GrAtlasTextBlob itself, plus size for the vertices array, |
| 21 | // and size for the glyphIds array. |
| 22 | size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize; |
| 23 | size_t size = sizeof(GrAtlasTextBlob) + |
| 24 | verticesCount + |
| 25 | glyphCount * sizeof(GrGlyph**) + |
| 26 | sizeof(GrAtlasTextBlob::Run) * runCount; |
| 27 | |
| 28 | void* allocation = pool->allocate(size); |
| 29 | if (CACHE_SANITY_CHECK) { |
| 30 | sk_bzero(allocation, size); |
| 31 | } |
| 32 | |
Florin Malita | c337c9e | 2017-03-10 18:02:29 +0000 | [diff] [blame] | 33 | sk_sp<GrAtlasTextBlob> cacheBlob(new (allocation) GrAtlasTextBlob); |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 34 | cacheBlob->fSize = size; |
| 35 | |
| 36 | // setup offsets for vertices / glyphs |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 37 | cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<char*>(cacheBlob.get()); |
joshualitt | 9230377 | 2016-02-10 11:55:52 -0800 | [diff] [blame] | 38 | cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + verticesCount); |
| 39 | cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyphs + glyphCount); |
| 40 | |
| 41 | // Initialize runs |
| 42 | for (int i = 0; i < runCount; i++) { |
| 43 | new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run; |
| 44 | } |
| 45 | cacheBlob->fRunCount = runCount; |
| 46 | cacheBlob->fPool = pool; |
| 47 | return cacheBlob; |
| 48 | } |
| 49 | |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 50 | SkGlyphCache* GrAtlasTextBlob::setupCache(int runIndex, |
| 51 | const SkSurfaceProps& props, |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame^] | 52 | SkScalerContextFlags scalerContextFlags, |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 53 | const SkPaint& skPaint, |
bungeman | f6d1e60 | 2016-02-22 13:20:28 -0800 | [diff] [blame] | 54 | const SkMatrix* viewMatrix) { |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 55 | GrAtlasTextBlob::Run* run = &fRuns[runIndex]; |
| 56 | |
| 57 | // if we have an override descriptor for the run, then we should use that |
| 58 | SkAutoDescriptor* desc = run->fOverrideDescriptor.get() ? run->fOverrideDescriptor.get() : |
| 59 | &run->fDescriptor; |
bsalomon | 8b6fa5e | 2016-05-19 16:23:47 -0700 | [diff] [blame] | 60 | SkScalerContextEffects effects; |
Herb Derby | d8327a8 | 2018-01-22 14:39:27 -0500 | [diff] [blame^] | 61 | skPaint.getScalerContextDescriptor(&effects, desc, &props, scalerContextFlags, viewMatrix); |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 62 | run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); |
bsalomon | 8b6fa5e | 2016-05-19 16:23:47 -0700 | [diff] [blame] | 63 | run->fPathEffect = sk_ref_sp(effects.fPathEffect); |
bsalomon | 8b6fa5e | 2016-05-19 16:23:47 -0700 | [diff] [blame] | 64 | run->fMaskFilter = sk_ref_sp(effects.fMaskFilter); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 65 | return SkGlyphCache::DetachCache(run->fTypeface.get(), effects, desc->getDesc()); |
joshualitt | e76b4bb3 | 2015-12-28 07:23:58 -0800 | [diff] [blame] | 66 | } |
| 67 | |
joshualitt | f528e0d | 2015-12-09 06:42:52 -0800 | [diff] [blame] | 68 | void GrAtlasTextBlob::appendGlyph(int runIndex, |
| 69 | const SkRect& positions, |
| 70 | GrColor color, |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 71 | GrAtlasTextStrike* strike, |
joshualitt | a06e6ab | 2015-12-10 08:54:41 -0800 | [diff] [blame] | 72 | GrGlyph* glyph, |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 73 | SkGlyphCache* cache, const SkGlyph& skGlyph, |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 74 | SkScalar x, SkScalar y, SkScalar scale, bool treatAsBMP) { |
Lee Salzman | 26d3f21 | 2017-01-27 14:31:10 -0500 | [diff] [blame] | 75 | if (positions.isEmpty()) { |
| 76 | return; |
| 77 | } |
joshualitt | a06e6ab | 2015-12-10 08:54:41 -0800 | [diff] [blame] | 78 | |
| 79 | // If the glyph is too large we fall back to paths |
| 80 | if (glyph->fTooLargeForAtlas) { |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 81 | this->appendBigGlyph(glyph, cache, skGlyph, x, y, scale, treatAsBMP); |
joshualitt | a06e6ab | 2015-12-10 08:54:41 -0800 | [diff] [blame] | 82 | return; |
| 83 | } |
| 84 | |
joshualitt | f528e0d | 2015-12-09 06:42:52 -0800 | [diff] [blame] | 85 | Run& run = fRuns[runIndex]; |
| 86 | GrMaskFormat format = glyph->fMaskFormat; |
| 87 | |
| 88 | Run::SubRunInfo* subRun = &run.fSubRunInfo.back(); |
| 89 | if (run.fInitialized && subRun->maskFormat() != format) { |
| 90 | subRun = &run.push_back(); |
| 91 | subRun->setStrike(strike); |
| 92 | } else if (!run.fInitialized) { |
| 93 | subRun->setStrike(strike); |
| 94 | } |
| 95 | |
| 96 | run.fInitialized = true; |
| 97 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 98 | bool hasW = subRun->hasWCoord(); |
| 99 | // DF glyphs drawn in perspective must always have a w coord. |
| 100 | SkASSERT(hasW || !subRun->drawAsDistanceFields() || !fInitialViewMatrix.hasPerspective()); |
| 101 | // Non-DF glyphs should never have a w coord. |
| 102 | SkASSERT(!hasW || subRun->drawAsDistanceFields()); |
| 103 | |
| 104 | size_t vertexStride = GetVertexStride(format, hasW); |
joshualitt | f528e0d | 2015-12-09 06:42:52 -0800 | [diff] [blame] | 105 | |
| 106 | subRun->setMaskFormat(format); |
| 107 | |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 108 | subRun->joinGlyphBounds(positions); |
joshualitt | f9e658b | 2015-12-09 09:26:44 -0800 | [diff] [blame] | 109 | subRun->setColor(color); |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 110 | |
| 111 | intptr_t vertex = reinterpret_cast<intptr_t>(this->fVertices + subRun->vertexEndIndex()); |
| 112 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 113 | // We always write the third position component used by SDFs. If it is unused it gets |
| 114 | // overwritten. Similarly, we always write the color and the blob will later overwrite it |
| 115 | // with texture coords if it is unused. |
| 116 | size_t colorOffset = hasW ? sizeof(SkPoint3) : sizeof(SkPoint); |
| 117 | // V0 |
| 118 | *reinterpret_cast<SkPoint3*>(vertex) = {positions.fLeft, positions.fTop, 1.f}; |
| 119 | *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; |
| 120 | vertex += vertexStride; |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 121 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 122 | // V1 |
| 123 | *reinterpret_cast<SkPoint3*>(vertex) = {positions.fLeft, positions.fBottom, 1.f}; |
| 124 | *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; |
| 125 | vertex += vertexStride; |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 126 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 127 | // V2 |
| 128 | *reinterpret_cast<SkPoint3*>(vertex) = {positions.fRight, positions.fTop, 1.f}; |
| 129 | *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; |
| 130 | vertex += vertexStride; |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 131 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 132 | // V3 |
| 133 | *reinterpret_cast<SkPoint3*>(vertex) = {positions.fRight, positions.fBottom, 1.f}; |
| 134 | *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 135 | |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame] | 136 | subRun->appendVertices(vertexStride); |
| 137 | fGlyphs[subRun->glyphEndIndex()] = glyph; |
| 138 | subRun->glyphAppended(); |
| 139 | } |
| 140 | |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 141 | void GrAtlasTextBlob::appendBigGlyph(GrGlyph* glyph, SkGlyphCache* cache, const SkGlyph& skGlyph, |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 142 | SkScalar x, SkScalar y, SkScalar scale, bool treatAsBMP) { |
joshualitt | a06e6ab | 2015-12-10 08:54:41 -0800 | [diff] [blame] | 143 | if (nullptr == glyph->fPath) { |
bsalomon | c2878e2 | 2016-05-17 13:18:03 -0700 | [diff] [blame] | 144 | const SkPath* glyphPath = cache->findPath(skGlyph); |
joshualitt | a06e6ab | 2015-12-10 08:54:41 -0800 | [diff] [blame] | 145 | if (!glyphPath) { |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | glyph->fPath = new SkPath(*glyphPath); |
| 150 | } |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 151 | fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y, scale, treatAsBMP)); |
joshualitt | a06e6ab | 2015-12-10 08:54:41 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 154 | bool GrAtlasTextBlob::mustRegenerate(const GrTextUtils::Paint& paint, |
| 155 | const SkMaskFilter::BlurRec& blurRec, |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 156 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { |
| 157 | // If we have LCD text then our canonical color will be set to transparent, in this case we have |
| 158 | // to regenerate the blob on any color change |
| 159 | // We use the grPaint to get any color filter effects |
| 160 | if (fKey.fCanonicalColor == SK_ColorTRANSPARENT && |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 161 | fLuminanceColor != paint.luminanceColor()) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 162 | return true; |
| 163 | } |
| 164 | |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 165 | if (fInitialViewMatrix.hasPerspective() != viewMatrix.hasPerspective()) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 166 | return true; |
| 167 | } |
| 168 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 169 | /** This could be relaxed for blobs with only distance field glyphs. */ |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 170 | if (fInitialViewMatrix.hasPerspective() && !fInitialViewMatrix.cheapEqualTo(viewMatrix)) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 171 | return true; |
| 172 | } |
| 173 | |
| 174 | // We only cache one masked version |
| 175 | if (fKey.fHasBlur && |
| 176 | (fBlurRec.fSigma != blurRec.fSigma || |
| 177 | fBlurRec.fStyle != blurRec.fStyle || |
| 178 | fBlurRec.fQuality != blurRec.fQuality)) { |
| 179 | return true; |
| 180 | } |
| 181 | |
| 182 | // Similarly, we only cache one version for each style |
| 183 | if (fKey.fStyle != SkPaint::kFill_Style && |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 184 | (fStrokeInfo.fFrameWidth != paint.skPaint().getStrokeWidth() || |
| 185 | fStrokeInfo.fMiterLimit != paint.skPaint().getStrokeMiter() || |
| 186 | fStrokeInfo.fJoin != paint.skPaint().getStrokeJoin())) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 187 | return true; |
| 188 | } |
| 189 | |
| 190 | // Mixed blobs must be regenerated. We could probably figure out a way to do integer scrolls |
| 191 | // for mixed blobs if this becomes an issue. |
| 192 | if (this->hasBitmap() && this->hasDistanceField()) { |
| 193 | // Identical viewmatrices and we can reuse in all cases |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 194 | if (fInitialViewMatrix.cheapEqualTo(viewMatrix) && x == fInitialX && y == fInitialY) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 195 | return false; |
| 196 | } |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | if (this->hasBitmap()) { |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 201 | if (fInitialViewMatrix.getScaleX() != viewMatrix.getScaleX() || |
| 202 | fInitialViewMatrix.getScaleY() != viewMatrix.getScaleY() || |
| 203 | fInitialViewMatrix.getSkewX() != viewMatrix.getSkewX() || |
| 204 | fInitialViewMatrix.getSkewY() != viewMatrix.getSkewY()) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 205 | return true; |
| 206 | } |
| 207 | |
| 208 | // We can update the positions in the cachedtextblobs without regenerating the whole blob, |
| 209 | // but only for integer translations. |
| 210 | // This cool bit of math will determine the necessary translation to apply to the already |
| 211 | // generated vertex coordinates to move them to the correct position |
| 212 | SkScalar transX = viewMatrix.getTranslateX() + |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 213 | viewMatrix.getScaleX() * (x - fInitialX) + |
| 214 | viewMatrix.getSkewX() * (y - fInitialY) - |
| 215 | fInitialViewMatrix.getTranslateX(); |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 216 | SkScalar transY = viewMatrix.getTranslateY() + |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 217 | viewMatrix.getSkewY() * (x - fInitialX) + |
| 218 | viewMatrix.getScaleY() * (y - fInitialY) - |
| 219 | fInitialViewMatrix.getTranslateY(); |
| 220 | if (!SkScalarIsInt(transX) || !SkScalarIsInt(transY)) { |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 221 | return true; |
| 222 | } |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 223 | } else if (this->hasDistanceField()) { |
| 224 | // A scale outside of [blob.fMaxMinScale, blob.fMinMaxScale] would result in a different |
| 225 | // distance field being generated, so we have to regenerate in those cases |
| 226 | SkScalar newMaxScale = viewMatrix.getMaxScale(); |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 227 | SkScalar oldMaxScale = fInitialViewMatrix.getMaxScale(); |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 228 | SkScalar scaleAdjust = newMaxScale / oldMaxScale; |
| 229 | if (scaleAdjust < fMaxMinScale || scaleAdjust > fMinMaxScale) { |
| 230 | return true; |
| 231 | } |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 232 | } |
| 233 | |
joshualitt | fd5f6c1 | 2015-12-10 07:44:50 -0800 | [diff] [blame] | 234 | // It is possible that a blob has neither distanceField nor bitmaptext. This is in the case |
| 235 | // when all of the runs inside the blob are drawn as paths. In this case, we always regenerate |
| 236 | // the blob anyways at flush time, so no need to regenerate explicitly |
| 237 | return false; |
| 238 | } |
| 239 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 240 | inline std::unique_ptr<GrAtlasTextOp> GrAtlasTextBlob::makeOp( |
Jim Van Verth | 56c3714 | 2017-10-31 14:44:25 -0400 | [diff] [blame] | 241 | const Run::SubRunInfo& info, int glyphCount, uint16_t run, uint16_t subRun, |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 242 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const SkIRect& clipRect, |
| 243 | const GrTextUtils::Paint& paint, const SkSurfaceProps& props, |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 244 | const GrDistanceFieldAdjustTable* distanceAdjustTable, GrAtlasGlyphCache* cache, |
| 245 | GrTextUtils::Target* target) { |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 246 | GrMaskFormat format = info.maskFormat(); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 247 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 248 | GrPaint grPaint; |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 249 | target->makeGrPaint(info.maskFormat(), paint, viewMatrix, &grPaint); |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 250 | std::unique_ptr<GrAtlasTextOp> op; |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 251 | if (info.drawAsDistanceFields()) { |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 252 | bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry()); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 253 | op = GrAtlasTextOp::MakeDistanceField( |
| 254 | std::move(grPaint), glyphCount, cache, distanceAdjustTable, |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 255 | target->colorSpaceInfo().isGammaCorrect(), paint.luminanceColor(), |
Brian Salomon | f3569f0 | 2017-10-24 12:52:33 -0400 | [diff] [blame] | 256 | info.hasUseLCDText(), useBGR, info.isAntiAliased()); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 257 | } else { |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 258 | op = GrAtlasTextOp::MakeBitmap(std::move(grPaint), format, glyphCount, cache); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 259 | } |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 260 | GrAtlasTextOp::Geometry& geometry = op->geometry(); |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 261 | geometry.fViewMatrix = viewMatrix; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 262 | geometry.fClipRect = clipRect; |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 263 | geometry.fBlob = SkRef(this); |
| 264 | geometry.fRun = run; |
| 265 | geometry.fSubRun = subRun; |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 266 | geometry.fColor = |
Brian Osman | ec8f8b0 | 2017-05-11 10:57:37 -0400 | [diff] [blame] | 267 | info.maskFormat() == kARGB_GrMaskFormat ? GrColor_WHITE : paint.filteredPremulColor(); |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 268 | geometry.fX = x; |
| 269 | geometry.fY = y; |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 270 | op->init(); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 271 | return op; |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 272 | } |
| 273 | |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 274 | inline void GrAtlasTextBlob::flushRun(GrTextUtils::Target* target, const GrClip& clip, int run, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 275 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, |
| 276 | const GrTextUtils::Paint& paint, const SkSurfaceProps& props, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 277 | const GrDistanceFieldAdjustTable* distanceAdjustTable, |
| 278 | GrAtlasGlyphCache* cache) { |
Jim Van Verth | 56c3714 | 2017-10-31 14:44:25 -0400 | [diff] [blame] | 279 | // GrAtlasTextBlob::makeOp only takes uint16_t values for run and subRun indices. |
| 280 | // Encountering something larger than this is highly unlikely, so we'll just not draw it. |
| 281 | if (run >= (1 << 16)) { |
| 282 | return; |
| 283 | } |
| 284 | int lastRun = SkTMin(fRuns[run].fSubRunInfo.count(), 1 << 16) - 1; |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 285 | for (int subRun = 0; subRun <= lastRun; subRun++) { |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 286 | const Run::SubRunInfo& info = fRuns[run].fSubRunInfo[subRun]; |
| 287 | int glyphCount = info.glyphCount(); |
| 288 | if (0 == glyphCount) { |
| 289 | continue; |
| 290 | } |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 291 | |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 292 | bool skipClip = false; |
| 293 | bool submitOp = true; |
| 294 | SkIRect clipRect = SkIRect::MakeEmpty(); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 295 | SkRect rtBounds = SkRect::MakeWH(target->width(), target->height()); |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 296 | SkRRect clipRRect; |
| 297 | GrAA aa; |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 298 | // We can clip geometrically if we're not using SDFs, |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 299 | // and we have an axis-aligned rectangular non-AA clip |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 300 | if (!info.drawAsDistanceFields() && clip.isRRect(rtBounds, &clipRRect, &aa) && |
| 301 | clipRRect.isRect() && GrAA::kNo == aa) { |
| 302 | skipClip = true; |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 303 | // We only need to do clipping work if the subrun isn't contained by the clip |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 304 | SkRect subRunBounds; |
| 305 | this->computeSubRunBounds(&subRunBounds, run, subRun, viewMatrix, x, y); |
| 306 | if (!clipRRect.getBounds().contains(subRunBounds)) { |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 307 | // If the subrun is completely outside, don't add an op for it |
| 308 | if (!clipRRect.getBounds().intersects(subRunBounds)) { |
| 309 | submitOp = false; |
| 310 | } else { |
| 311 | clipRRect.getBounds().round(&clipRect); |
| 312 | } |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 316 | if (submitOp) { |
| 317 | auto op = this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, clipRect, |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 318 | std::move(paint), props, distanceAdjustTable, cache, target); |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 319 | if (op) { |
| 320 | if (skipClip) { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 321 | target->addDrawOp(GrNoClip(), std::move(op)); |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 322 | } else { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 323 | target->addDrawOp(clip, std::move(op)); |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 324 | } |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 325 | } |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 326 | } |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 330 | static void calculate_translation(bool applyVM, |
| 331 | const SkMatrix& newViewMatrix, SkScalar newX, SkScalar newY, |
| 332 | const SkMatrix& currentViewMatrix, SkScalar currentX, |
| 333 | SkScalar currentY, SkScalar* transX, SkScalar* transY) { |
| 334 | if (applyVM) { |
| 335 | *transX = newViewMatrix.getTranslateX() + |
| 336 | newViewMatrix.getScaleX() * (newX - currentX) + |
| 337 | newViewMatrix.getSkewX() * (newY - currentY) - |
| 338 | currentViewMatrix.getTranslateX(); |
| 339 | |
| 340 | *transY = newViewMatrix.getTranslateY() + |
| 341 | newViewMatrix.getSkewY() * (newX - currentX) + |
| 342 | newViewMatrix.getScaleY() * (newY - currentY) - |
| 343 | currentViewMatrix.getTranslateY(); |
| 344 | } else { |
| 345 | *transX = newX - currentX; |
| 346 | *transY = newY - currentY; |
| 347 | } |
| 348 | } |
| 349 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 350 | void GrAtlasTextBlob::flushBigGlyphs(GrTextUtils::Target* target, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 351 | const GrClip& clip, const SkPaint& paint, |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 352 | const SkMatrix& viewMatrix, SkScalar x, SkScalar y, |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 353 | const SkIRect& clipBounds) { |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 354 | SkScalar transX, transY; |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 355 | for (int i = 0; i < fBigGlyphs.count(); i++) { |
| 356 | GrAtlasTextBlob::BigGlyph& bigGlyph = fBigGlyphs[i]; |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 357 | calculate_translation(bigGlyph.fTreatAsBMP, viewMatrix, x, y, |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 358 | fInitialViewMatrix, fInitialX, fInitialY, &transX, &transY); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 359 | SkMatrix ctm; |
| 360 | ctm.setScale(bigGlyph.fScale, bigGlyph.fScale); |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 361 | ctm.postTranslate(bigGlyph.fX + transX, bigGlyph.fY + transY); |
Jim Van Verth | 08576e6 | 2016-11-16 10:15:23 -0500 | [diff] [blame] | 362 | if (!bigGlyph.fTreatAsBMP) { |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 363 | ctm.postConcat(viewMatrix); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 364 | } |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 365 | target->drawPath(clip, bigGlyph.fPath, paint, ctm, nullptr, clipBounds); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 369 | void GrAtlasTextBlob::flushBigRun(GrTextUtils::Target* target, |
| 370 | const SkSurfaceProps& props, const SkTextBlobRunIterator& it, |
| 371 | const GrClip& clip, const GrTextUtils::Paint& paint, |
| 372 | SkDrawFilter* drawFilter, const SkMatrix& viewMatrix, |
| 373 | const SkIRect& clipBounds, SkScalar x, SkScalar y) { |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 374 | size_t textLen = it.glyphCount() * sizeof(uint16_t); |
| 375 | const SkPoint& offset = it.offset(); |
| 376 | |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 377 | GrTextUtils::RunPaint runPaint(&paint, drawFilter, props); |
| 378 | if (!runPaint.modifyForRun(it)) { |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 379 | return; |
| 380 | } |
| 381 | |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 382 | switch (it.positioning()) { |
| 383 | case SkTextBlob::kDefault_Positioning: |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 384 | GrTextUtils::DrawBigText(target, clip, runPaint, viewMatrix, |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 385 | (const char*)it.glyphs(), textLen, x + offset.x(), |
| 386 | y + offset.y(), clipBounds); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 387 | break; |
| 388 | case SkTextBlob::kHorizontal_Positioning: |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 389 | GrTextUtils::DrawBigPosText(target, props, clip, runPaint, viewMatrix, |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 390 | (const char*)it.glyphs(), textLen, it.pos(), 1, |
| 391 | SkPoint::Make(x, y + offset.y()), clipBounds); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 392 | break; |
| 393 | case SkTextBlob::kFull_Positioning: |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 394 | GrTextUtils::DrawBigPosText(target, props, clip, runPaint, viewMatrix, |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 395 | (const char*)it.glyphs(), textLen, it.pos(), 2, |
| 396 | SkPoint::Make(x, y), clipBounds); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 397 | break; |
| 398 | } |
| 399 | } |
| 400 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 401 | void GrAtlasTextBlob::flushCached(GrAtlasGlyphCache* atlasGlyphCache, GrTextUtils::Target* target, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 402 | const SkTextBlob* blob, const SkSurfaceProps& props, |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 403 | const GrDistanceFieldAdjustTable* distanceAdjustTable, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 404 | const GrTextUtils::Paint& paint, SkDrawFilter* drawFilter, |
| 405 | const GrClip& clip, const SkMatrix& viewMatrix, |
| 406 | const SkIRect& clipBounds, SkScalar x, SkScalar y) { |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 407 | // We loop through the runs of the blob, flushing each. If any run is too large, then we flush |
| 408 | // it as paths |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 409 | SkTextBlobRunIterator it(blob); |
| 410 | for (int run = 0; !it.done(); it.next(), run++) { |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 411 | if (fRuns[run].fTooBigForAtlas) { |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 412 | this->flushBigRun(target, props, it, clip, paint, drawFilter, viewMatrix, |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 413 | clipBounds, x, y); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 414 | continue; |
| 415 | } |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 416 | this->flushRun(target, clip, run, viewMatrix, x, y, paint, props, distanceAdjustTable, |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 417 | atlasGlyphCache); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | // Now flush big glyphs |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 421 | this->flushBigGlyphs(target, clip, paint, viewMatrix, x, y, clipBounds); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 422 | } |
| 423 | |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 424 | void GrAtlasTextBlob::flushThrowaway(GrAtlasGlyphCache* atlasGlyphCache, |
| 425 | GrTextUtils::Target* target, |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 426 | const SkSurfaceProps& props, |
| 427 | const GrDistanceFieldAdjustTable* distanceAdjustTable, |
Brian Salomon | 6f1d36c | 2017-01-13 12:02:17 -0500 | [diff] [blame] | 428 | const GrTextUtils::Paint& paint, const GrClip& clip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 429 | const SkMatrix& viewMatrix, const SkIRect& clipBounds, |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 430 | SkScalar x, SkScalar y) { |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 431 | for (int run = 0; run < fRunCount; run++) { |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 432 | this->flushRun(target, clip, run, viewMatrix, x, y, paint, props, distanceAdjustTable, |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 433 | atlasGlyphCache); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | // Now flush big glyphs |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 437 | this->flushBigGlyphs(target, clip, paint, viewMatrix, x, y, clipBounds); |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 440 | std::unique_ptr<GrDrawOp> GrAtlasTextBlob::test_makeOp( |
Jim Van Verth | 56c3714 | 2017-10-31 14:44:25 -0400 | [diff] [blame] | 441 | int glyphCount, uint16_t run, uint16_t subRun, const SkMatrix& viewMatrix, |
| 442 | SkScalar x, SkScalar y, const GrTextUtils::Paint& paint, const SkSurfaceProps& props, |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 443 | const GrDistanceFieldAdjustTable* distanceAdjustTable, GrAtlasGlyphCache* cache, |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 444 | GrTextUtils::Target* target) { |
joshualitt | 7481e75 | 2016-01-22 06:08:48 -0800 | [diff] [blame] | 445 | const GrAtlasTextBlob::Run::SubRunInfo& info = fRuns[run].fSubRunInfo[subRun]; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 446 | SkIRect emptyRect = SkIRect::MakeEmpty(); |
Brian Salomon | f18b1d8 | 2017-10-27 11:30:49 -0400 | [diff] [blame] | 447 | return this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, emptyRect, paint, props, |
| 448 | distanceAdjustTable, cache, target); |
joshualitt | 323c2eb | 2016-01-20 06:48:47 -0800 | [diff] [blame] | 449 | } |
joshualitt | 2e2202e | 2015-12-10 11:22:08 -0800 | [diff] [blame] | 450 | |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 451 | void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) { |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 452 | SkASSERT_RELEASE(l.fSize == r.fSize); |
| 453 | SkASSERT_RELEASE(l.fPool == r.fPool); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 454 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 455 | SkASSERT_RELEASE(l.fBlurRec.fSigma == r.fBlurRec.fSigma); |
| 456 | SkASSERT_RELEASE(l.fBlurRec.fStyle == r.fBlurRec.fStyle); |
| 457 | SkASSERT_RELEASE(l.fBlurRec.fQuality == r.fBlurRec.fQuality); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 458 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 459 | SkASSERT_RELEASE(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth); |
| 460 | SkASSERT_RELEASE(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit); |
| 461 | SkASSERT_RELEASE(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 462 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 463 | SkASSERT_RELEASE(l.fBigGlyphs.count() == r.fBigGlyphs.count()); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 464 | for (int i = 0; i < l.fBigGlyphs.count(); i++) { |
| 465 | const BigGlyph& lBigGlyph = l.fBigGlyphs[i]; |
| 466 | const BigGlyph& rBigGlyph = r.fBigGlyphs[i]; |
| 467 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 468 | SkASSERT_RELEASE(lBigGlyph.fPath == rBigGlyph.fPath); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 469 | // We can't assert that these have the same translations |
| 470 | } |
| 471 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 472 | SkASSERT_RELEASE(l.fKey == r.fKey); |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 473 | //SkASSERT_RELEASE(l.fPaintColor == r.fPaintColor); // Colors might not actually be identical |
| 474 | SkASSERT_RELEASE(l.fMaxMinScale == r.fMaxMinScale); |
| 475 | SkASSERT_RELEASE(l.fMinMaxScale == r.fMinMaxScale); |
| 476 | SkASSERT_RELEASE(l.fTextType == r.fTextType); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 477 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 478 | SkASSERT_RELEASE(l.fRunCount == r.fRunCount); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 479 | for (int i = 0; i < l.fRunCount; i++) { |
| 480 | const Run& lRun = l.fRuns[i]; |
| 481 | const Run& rRun = r.fRuns[i]; |
| 482 | |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 483 | if (lRun.fTypeface.get()) { |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 484 | SkASSERT_RELEASE(rRun.fTypeface.get()); |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 485 | SkASSERT_RELEASE(SkTypeface::Equal(lRun.fTypeface.get(), rRun.fTypeface.get())); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 486 | } else { |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 487 | SkASSERT_RELEASE(!rRun.fTypeface.get()); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 488 | } |
| 489 | |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 490 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 491 | SkASSERT_RELEASE(lRun.fDescriptor.getDesc()); |
| 492 | SkASSERT_RELEASE(rRun.fDescriptor.getDesc()); |
bsalomon | c5d07fa | 2016-05-17 10:17:45 -0700 | [diff] [blame] | 493 | SkASSERT_RELEASE(*lRun.fDescriptor.getDesc() == *rRun.fDescriptor.getDesc()); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 494 | |
| 495 | if (lRun.fOverrideDescriptor.get()) { |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 496 | SkASSERT_RELEASE(lRun.fOverrideDescriptor->getDesc()); |
| 497 | SkASSERT_RELEASE(rRun.fOverrideDescriptor.get() && rRun.fOverrideDescriptor->getDesc()); |
bsalomon | c5d07fa | 2016-05-17 10:17:45 -0700 | [diff] [blame] | 498 | SkASSERT_RELEASE(*lRun.fOverrideDescriptor->getDesc() == |
| 499 | *rRun.fOverrideDescriptor->getDesc()); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 500 | } else { |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 501 | SkASSERT_RELEASE(!rRun.fOverrideDescriptor.get()); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | // color can be changed |
| 505 | //SkASSERT(lRun.fColor == rRun.fColor); |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 506 | SkASSERT_RELEASE(lRun.fInitialized == rRun.fInitialized); |
Jim Van Verth | f4c1316 | 2018-01-11 16:40:24 -0500 | [diff] [blame] | 507 | SkASSERT_RELEASE(lRun.fTooBigForAtlas == rRun.fTooBigForAtlas); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 508 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 509 | SkASSERT_RELEASE(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count()); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 510 | for(int j = 0; j < lRun.fSubRunInfo.count(); j++) { |
| 511 | const Run::SubRunInfo& lSubRun = lRun.fSubRunInfo[j]; |
| 512 | const Run::SubRunInfo& rSubRun = rRun.fSubRunInfo[j]; |
| 513 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 514 | // TODO we can do this check, but we have to apply the VM to the old vertex bounds |
| 515 | //SkASSERT_RELEASE(lSubRun.vertexBounds() == rSubRun.vertexBounds()); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 516 | |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 517 | if (lSubRun.strike()) { |
| 518 | SkASSERT_RELEASE(rSubRun.strike()); |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 519 | SkASSERT_RELEASE(GrAtlasTextStrike::GetKey(*lSubRun.strike()) == |
| 520 | GrAtlasTextStrike::GetKey(*rSubRun.strike())); |
joshualitt | 2f2ee83 | 2016-02-10 08:52:24 -0800 | [diff] [blame] | 521 | |
| 522 | } else { |
| 523 | SkASSERT_RELEASE(!rSubRun.strike()); |
| 524 | } |
| 525 | |
| 526 | SkASSERT_RELEASE(lSubRun.vertexStartIndex() == rSubRun.vertexStartIndex()); |
| 527 | SkASSERT_RELEASE(lSubRun.vertexEndIndex() == rSubRun.vertexEndIndex()); |
| 528 | SkASSERT_RELEASE(lSubRun.glyphStartIndex() == rSubRun.glyphStartIndex()); |
| 529 | SkASSERT_RELEASE(lSubRun.glyphEndIndex() == rSubRun.glyphEndIndex()); |
| 530 | SkASSERT_RELEASE(lSubRun.maskFormat() == rSubRun.maskFormat()); |
| 531 | SkASSERT_RELEASE(lSubRun.drawAsDistanceFields() == rSubRun.drawAsDistanceFields()); |
| 532 | SkASSERT_RELEASE(lSubRun.hasUseLCDText() == rSubRun.hasUseLCDText()); |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | } |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 536 | |
| 537 | void GrAtlasTextBlob::Run::SubRunInfo::computeTranslation(const SkMatrix& viewMatrix, |
| 538 | SkScalar x, SkScalar y, SkScalar* transX, |
| 539 | SkScalar* transY) { |
| 540 | calculate_translation(!this->drawAsDistanceFields(), viewMatrix, x, y, |
| 541 | fCurrentViewMatrix, fX, fY, transX, transY); |
| 542 | fCurrentViewMatrix = viewMatrix; |
| 543 | fX = x; |
| 544 | fY = y; |
| 545 | } |