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