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