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