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