From 59d997a6e1d32f2d0a3021931aed87984d15a7ee Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Thu, 7 Jun 2018 12:44:09 -0400 Subject: New more efficient run builder A system for building glyph runs. In the future the builder will only live in canvas, but it's internal structures facilitate interacting with the cache a single glyph at a time. When all the bulk code is in place, only runs will be passed around. Passing the builder down the text draw stack is temporary. Change-Id: I6e3ed184b3f3a58b919377f2d31936e971bd8efa Reviewed-on: https://skia-review.googlesource.com/132928 Reviewed-by: Herb Derby Reviewed-by: Mike Klein Commit-Queue: Herb Derby --- src/gpu/text/GrTextContext.cpp | 60 ++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 25 deletions(-) (limited to 'src/gpu/text') diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp index 9864d027de..b8fe456b79 100644 --- a/src/gpu/text/GrTextContext.cpp +++ b/src/gpu/text/GrTextContext.cpp @@ -210,15 +210,18 @@ void GrTextContext::regenerateTextBlob(GrTextBlob* cacheBlob, shaderCaps.supportsDistanceFieldText(), fOptions)) { switch (it.positioning()) { case SkTextBlob::kDefault_Positioning: { - SkGlyphSet glyphSet; auto origin = SkPoint::Make(x + offset.x(), y + offset.y()); - auto glyphRun = - SkGlyphRun::MakeFromDrawText(runPaint.skPaint(), - (const char*)it.glyphs(), textLen, origin, &glyphSet); - - this->drawDFPosText(cacheBlob, run, glyphCache, props, runPaint, - scalerContextFlags, viewMatrix, (const char*)it.glyphs(), - textLen, glyphRun.getPositions(), 2, SkPoint::Make(0,0)); + SkGlyphRunBuilder builder; + builder.prepareDrawText(runPaint.skPaint(), + (const char*)it.glyphs(), textLen, origin); + + builder.temporaryShuntToCallback( + [&](size_t runSize, const char* glyphIDs, const SkScalar* pos) { + this->drawDFPosText( + cacheBlob, run, glyphCache, props, runPaint, scalerContextFlags, + viewMatrix, glyphIDs, 2 * runSize, pos, 2, + SkPoint::Make(0,0)); + }); break; } @@ -240,16 +243,18 @@ void GrTextContext::regenerateTextBlob(GrTextBlob* cacheBlob, } else { switch (it.positioning()) { case SkTextBlob::kDefault_Positioning: { - SkGlyphSet glyphSet; auto origin = SkPoint::Make(x + offset.x(), y + offset.y()); - auto glyphRun = - SkGlyphRun::MakeFromDrawText( - runPaint.skPaint(), (const char*) it.glyphs(), textLen, origin, - &glyphSet); - - this->DrawBmpPosText(cacheBlob, run, glyphCache, props, runPaint, - scalerContextFlags, viewMatrix, (const char*) it.glyphs(), - textLen, glyphRun.getPositions(), 2, SkPoint::Make(0, 0)); + SkGlyphRunBuilder builder; + builder.prepareDrawText(runPaint.skPaint(), + (const char*)it.glyphs(), textLen, origin); + + builder.temporaryShuntToCallback( + [&](size_t runSize, const char* glyphIDs, const SkScalar* pos) { + this->DrawBmpPosText( + cacheBlob, run, glyphCache, props, runPaint, scalerContextFlags, + viewMatrix, glyphIDs, 2 * runSize, + pos, 2, SkPoint::Make(0, 0)); + }); break; } case SkTextBlob::kHorizontal_Positioning: @@ -768,15 +773,20 @@ std::unique_ptr GrTextContext::createOp_TestingOnly(GrContext* context // right now we don't handle textblobs, nor do we handle drawPosText. Since we only intend to // test the text op with this unit test, that is okay. - SkGlyphSet glyphSet; auto origin = SkPoint::Make(x, y); - auto glyphRun = SkGlyphRun::MakeFromDrawText(skPaint, text, textLen, origin, &glyphSet); - - sk_sp blob(textContext->makeDrawPosTextBlob( - context->contextPriv().getTextBlobCache(), glyphCache, - *context->contextPriv().caps()->shaderCaps(), utilsPaint, - GrTextContext::kTextBlobOpScalerContextFlags, viewMatrix, surfaceProps, text, - static_cast(textLen), glyphRun.getPositions(), 2, origin)); + SkGlyphRunBuilder builder; + builder.prepareDrawText(skPaint, text, textLen, origin); + sk_sp blob; + + // Use the text and textLen below, because we don't want to mess with the paint. + builder.temporaryShuntToCallback( + [&](size_t runSize, const char* glyphIDs, const SkScalar* pos) { + blob = textContext->makeDrawPosTextBlob( + context->contextPriv().getTextBlobCache(), glyphCache, + *context->contextPriv().caps()->shaderCaps(), utilsPaint, + GrTextContext::kTextBlobOpScalerContextFlags, viewMatrix, surfaceProps, text, + textLen, pos, 2, origin); + }); return blob->test_makeOp(textLen, 0, 0, viewMatrix, x, y, utilsPaint, surfaceProps, textContext->dfAdjustTable(), rtc->textTarget()); -- cgit v1.2.3