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