From f9dfbc3ec1d8d5c1ba961698ee1bc34bc1ee7229 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Sat, 28 Jul 2018 16:16:56 -0400 Subject: Combine GPU drawing routines into one large routine Combining drawDFGlyphRun, DrawBmpGlyphRunAsPaths, and DrawBmpGlyphRun into regenerateGlyphRunList represents the code that must be encapsulated into SkGlyphRunListDrawer. Change-Id: Ia0a710200d8ca7f66495d220698915d87de5a079 Reviewed-on: https://skia-review.googlesource.com/144301 Commit-Queue: Herb Derby Reviewed-by: Mike Klein --- src/gpu/text/GrTextContext.cpp | 228 ++++++++++++++++++----------------------- src/gpu/text/GrTextContext.h | 18 ---- 2 files changed, 100 insertions(+), 146 deletions(-) diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp index 4ad29f3a38..7b15abc666 100644 --- a/src/gpu/text/GrTextContext.cpp +++ b/src/gpu/text/GrTextContext.cpp @@ -85,126 +85,6 @@ SkScalerContextFlags GrTextContext::ComputeScalerContextFlags( } -void GrTextContext::drawDFGlyphRun(GrTextBlob* blob, int runIndex, - GrGlyphCache* glyphCache, const SkSurfaceProps& props, - const GrTextUtils::Paint& paint, - SkScalerContextFlags scalerContextFlags, - const SkMatrix& viewMatrix, const SkGlyphRun& glyphRun, - const SkPoint& offset) const { - bool hasWCoord = viewMatrix.hasPerspective() || fOptions.fDistanceFieldVerticesAlwaysHaveW; - - // Setup distance field paint and text ratio - SkScalar textRatio; - SkPaint dfPaint(paint); - SkScalerContextFlags flags; - InitDistanceFieldPaint(blob, &dfPaint, viewMatrix, fOptions, &textRatio, &flags); - blob->setHasDistanceField(); - blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(), - paint.skPaint().isAntiAlias(), hasWCoord); - - FallbackGlyphRunHelper fallbackTextHelper(viewMatrix, paint, glyphCache->getGlyphSizeLimit(), - textRatio); - - sk_sp currStrike; - - { - auto cache = blob->setupCache(runIndex, props, flags, dfPaint, nullptr); - - const SkPoint* positionCursor = glyphRun.positions().data(); - for (auto glyphID : glyphRun.shuntGlyphsIDs()) { - const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID); - SkPoint glyphPos = offset + *positionCursor++; - if (glyph.fWidth > 0) { - if (glyph.fMaskFormat == SkMask::kSDF_Format) { - DfAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph, glyphPos.fX, - glyphPos.fY, paint.filteredPremulColor(), cache.get(), textRatio); - } else { - // can't append non-SDF glyph to SDF batch, send to fallback - fallbackTextHelper.appendText(glyph, glyphID, glyphPos); - } - } - } - } - - fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, paint, scalerContextFlags); -} - -void GrTextContext::DrawBmpGlyphRunAsPaths(GrTextBlob* blob, int runIndex, - GrGlyphCache* glyphCache, - const SkSurfaceProps& props, - const GrTextUtils::Paint& origPaint, - SkScalerContextFlags scalerContextFlags, - const SkMatrix& viewMatrix, - const SkGlyphRun& glyphRun, - const SkPoint& offset) { - - // setup our std paint, in hopes of getting hits in the cache - SkPaint pathPaint(origPaint); - SkScalar matrixScale = pathPaint.setupForAsPaths(); - - FallbackGlyphRunHelper fallbackTextHelper( - viewMatrix, origPaint, glyphCache->getGlyphSizeLimit(), matrixScale); - - // Temporarily jam in kFill, so we only ever ask for the raw outline from the cache. - pathPaint.setStyle(SkPaint::kFill_Style); - pathPaint.setPathEffect(nullptr); - - auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( - pathPaint, &props, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr); - - const SkPoint* positionCursor = glyphRun.positions().data(); - for (auto glyphID : glyphRun.shuntGlyphsIDs()) { - const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID); - SkPoint loc = offset + *positionCursor++; - if (glyph.fWidth > 0) { - if (glyph.fMaskFormat == SkMask::kARGB32_Format) { - fallbackTextHelper.appendText(glyph, glyphID, loc); - } else { - const SkPath* path = cache->findPath(glyph); - if (path != nullptr) { - blob->appendPathGlyph(runIndex, *path, loc.fX, loc.fY, matrixScale, false); - } - } - } - } - - fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, origPaint, scalerContextFlags); -} - -void GrTextContext::DrawBmpGlyphRun(GrTextBlob* blob, int runIndex, - GrGlyphCache* glyphCache, const SkSurfaceProps& props, - const GrTextUtils::Paint& paint, - SkScalerContextFlags scalerContextFlags, - const SkMatrix& viewMatrix, - const SkGlyphRun& glyphRun, const SkPoint& offset) { - - // Ensure the blob is set for bitmaptext - blob->setHasBitmap(); - - if (SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix)) { - DrawBmpGlyphRunAsPaths( - blob, runIndex, glyphCache, props, paint, scalerContextFlags, viewMatrix, - glyphRun, offset); - return; - } - - sk_sp currStrike; - auto cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix); - SkFindAndPlaceGlyph::ProcessPosText( - SkPaint::kGlyphID_TextEncoding, - (const char*)glyphRun.shuntGlyphsIDs().data(), - glyphRun.shuntGlyphsIDs().size() * sizeof(SkGlyphID), - offset, viewMatrix, (const SkScalar*)glyphRun.positions().data(), 2, cache.get(), - [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { - position += rounding; - BmpAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph, - SkScalarFloorToScalar(position.fX), - SkScalarFloorToScalar(position.fY), - paint.filteredPremulColor(), cache.get(), SK_Scalar1, false); - } - ); -} - void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, GrGlyphCache* glyphCache, const GrShaderCaps& shaderCaps, @@ -218,24 +98,116 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, // Regenerate textblob GrTextUtils::RunPaint runPaint(&paint); - int runNum = 0; + int runIndex = 0; for (const auto& glyphRun : glyphRunList) { - cacheBlob->push_back_run(runNum); + cacheBlob->push_back_run(runIndex); if (!runPaint.modifyForRun([glyphRun](SkPaint* p) { *p = glyphRun.paint(); })) { continue; } - cacheBlob->setRunPaintFlags(runNum, runPaint.skPaint().getFlags()); + cacheBlob->setRunPaintFlags(runIndex, runPaint.skPaint().getFlags()); if (CanDrawAsDistanceFields(runPaint, viewMatrix, props, shaderCaps.supportsDistanceFieldText(), fOptions)) { - this->drawDFGlyphRun(cacheBlob, runNum, glyphCache, props, runPaint, - scalerContextFlags, viewMatrix, glyphRun, origin); + bool hasWCoord = viewMatrix.hasPerspective() + || fOptions.fDistanceFieldVerticesAlwaysHaveW; + + // Setup distance field runPaint and text ratio + SkScalar textRatio; + SkPaint dfPaint(runPaint); + SkScalerContextFlags flags; + InitDistanceFieldPaint(cacheBlob, &dfPaint, viewMatrix, fOptions, &textRatio, &flags); + cacheBlob->setHasDistanceField(); + cacheBlob->setSubRunHasDistanceFields(runIndex, runPaint.skPaint().isLCDRenderText(), + runPaint.skPaint().isAntiAlias(), hasWCoord); + + FallbackGlyphRunHelper fallbackTextHelper( + viewMatrix, runPaint, glyphCache->getGlyphSizeLimit(), textRatio); + + sk_sp currStrike; + + { + auto cache = cacheBlob->setupCache(runIndex, props, flags, dfPaint, nullptr); + + const SkPoint* positionCursor = glyphRun.positions().data(); + for (auto glyphID : glyphRun.shuntGlyphsIDs()) { + const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID); + SkPoint glyphPos = origin + *positionCursor++; + if (glyph.fWidth > 0) { + if (glyph.fMaskFormat == SkMask::kSDF_Format) { + DfAppendGlyph( + cacheBlob, runIndex, glyphCache, &currStrike, glyph, + glyphPos.fX, glyphPos.fY, runPaint.filteredPremulColor(), + cache.get(), textRatio); + } else { + // can't append non-SDF glyph to SDF batch, send to fallback + fallbackTextHelper.appendText(glyph, glyphID, glyphPos); + } + } + } + } + + fallbackTextHelper.drawText( + cacheBlob, runIndex, glyphCache, props, runPaint, scalerContextFlags); + + } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) { + // Ensure the blob is set for bitmaptext + cacheBlob->setHasBitmap(); + + // setup our std runPaint, in hopes of getting hits in the cache + SkPaint pathPaint(runPaint); + SkScalar matrixScale = pathPaint.setupForAsPaths(); + + FallbackGlyphRunHelper fallbackTextHelper( + viewMatrix, runPaint, glyphCache->getGlyphSizeLimit(), matrixScale); + + // Temporarily jam in kFill, so we only ever ask for the raw outline from the cache. + pathPaint.setStyle(SkPaint::kFill_Style); + pathPaint.setPathEffect(nullptr); + + auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( + pathPaint, &props, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr); + + const SkPoint* positionCursor = glyphRun.positions().data(); + for (auto glyphID : glyphRun.shuntGlyphsIDs()) { + const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID); + SkPoint loc = origin + *positionCursor++; + if (glyph.fWidth > 0) { + if (glyph.fMaskFormat == SkMask::kARGB32_Format) { + fallbackTextHelper.appendText(glyph, glyphID, loc); + } else { + const SkPath* path = cache->findPath(glyph); + if (path != nullptr) { + cacheBlob->appendPathGlyph(runIndex, *path, loc.fX, loc.fY, matrixScale, false); + } + } + } + } + + fallbackTextHelper.drawText( + cacheBlob, runIndex, glyphCache, props, runPaint, scalerContextFlags); + } else { - DrawBmpGlyphRun(cacheBlob, runNum, glyphCache, props, runPaint, scalerContextFlags, - viewMatrix, glyphRun, origin); + // Ensure the blob is set for bitmaptext + cacheBlob->setHasBitmap(); + sk_sp currStrike; + auto cache = cacheBlob->setupCache( + runIndex, props, scalerContextFlags, runPaint, &viewMatrix); + SkFindAndPlaceGlyph::ProcessPosText( + SkPaint::kGlyphID_TextEncoding, + (const char*) glyphRun.shuntGlyphsIDs().data(), + glyphRun.shuntGlyphsIDs().size() * sizeof(SkGlyphID), + origin, viewMatrix, (const SkScalar*) glyphRun.positions().data(), 2, cache.get(), + [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { + position += rounding; + BmpAppendGlyph(cacheBlob, runIndex, glyphCache, &currStrike, glyph, + SkScalarFloorToScalar(position.fX), + SkScalarFloorToScalar(position.fY), + runPaint.filteredPremulColor(), cache.get(), SK_Scalar1, false); + } + ); } - runNum += 1; + runIndex += 1; } } diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h index 6bfa718712..2794a84b82 100644 --- a/src/gpu/text/GrTextContext.h +++ b/src/gpu/text/GrTextContext.h @@ -151,24 +151,6 @@ private: // Determines if we need to use fake gamma (and contrast boost): static SkScalerContextFlags ComputeScalerContextFlags(const GrColorSpaceInfo&); - void drawDFGlyphRun(GrTextBlob* blob, int runIndex, GrGlyphCache*, - const SkSurfaceProps&, const GrTextUtils::Paint& paint, - SkScalerContextFlags scalerContextFlags, - const SkMatrix& viewMatrix, const SkGlyphRun& glyphRun, - const SkPoint& offset) const; - - static void DrawBmpGlyphRunAsPaths(GrTextBlob*, int runIndex, GrGlyphCache*, - const SkSurfaceProps&, const GrTextUtils::Paint& paint, - SkScalerContextFlags scalerContextFlags, - const SkMatrix& viewMatrix, - const SkGlyphRun& glyphRun, - const SkPoint& offset); - - static void DrawBmpGlyphRun(GrTextBlob*, int runIndex, GrGlyphCache*, - const SkSurfaceProps&, const GrTextUtils::Paint& paint, - SkScalerContextFlags scalerContextFlags, const SkMatrix& viewMatrix, - const SkGlyphRun& glyphRun, const SkPoint& offset); - void regenerateGlyphRunList(GrTextBlob* bmp, GrGlyphCache*, const GrShaderCaps&, -- cgit v1.2.3