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