From dc214c2cb55d03a7162ff39166cce0994c703b3d Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Thu, 8 Nov 2018 13:31:39 -0500 Subject: [PATCH] Move (re)generation of the GrTextBlob from GrTextContext to the blob This resolves many scoping issues, which complicate this code. Change-Id: Ib0d283d95ff8a563176a333c8d388947650df4d2 Reviewed-on: https://skia-review.googlesource.com/c/169761 Reviewed-by: Mike Klein Commit-Queue: Herb Derby --- src/core/SkGlyphRunPainter.cpp | 108 +++++++++++++++---------------- src/gpu/GrDrawingManager.h | 2 + src/gpu/ops/GrAtlasTextOp.h | 2 +- src/gpu/text/GrTextBlob.h | 15 ++++- src/gpu/text/GrTextBlobCache.h | 2 +- src/gpu/text/GrTextContext.h | 20 +----- tests/SkRemoteGlyphCacheTest.cpp | 1 + 7 files changed, 74 insertions(+), 76 deletions(-) diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp index a38e4ddf51..e3900aa1d6 100644 --- a/src/core/SkGlyphRunPainter.cpp +++ b/src/core/SkGlyphRunPainter.cpp @@ -517,10 +517,10 @@ void GrTextContext::drawGlyphRunList( // but we'd have to clear the subrun information textBlobCache->remove(cacheBlob.get()); cacheBlob = textBlobCache->makeCachedBlob(glyphRunList, key, blurRec, listPaint); - this->regenerateGlyphRunList(cacheBlob.get(), glyphCache, - *context->contextPriv().caps()->shaderCaps(), listPaint, - filteredColor, scalerContextFlags, viewMatrix, props, - glyphRunList, target->glyphPainter()); + cacheBlob->generateFromGlyphRunList( + glyphCache, *context->contextPriv().caps()->shaderCaps(), fOptions, + listPaint, filteredColor, scalerContextFlags, viewMatrix, props, + glyphRunList, target->glyphPainter()); } else { textBlobCache->makeMRU(cacheBlob.get()); @@ -529,8 +529,8 @@ void GrTextContext::drawGlyphRunList( int runCount = glyphRunList.runCount(); sk_sp sanityBlob(textBlobCache->makeBlob(glyphCount, runCount)); sanityBlob->setupKey(key, blurRec, listPaint); - this->regenerateGlyphRunList( - sanityBlob.get(), glyphCache, *context->contextPriv().caps()->shaderCaps(), + cacheBlob->generateFromGlyphRunList( + glyphCache, *context->contextPriv().caps()->shaderCaps(), fOptions, listPaint, filteredColor, scalerContextFlags, viewMatrix, props, glyphRunList, target->glyphPainter()); GrTextBlob::AssertEqual(*sanityBlob, *cacheBlob); @@ -542,17 +542,17 @@ void GrTextContext::drawGlyphRunList( } else { cacheBlob = textBlobCache->makeBlob(glyphRunList); } - this->regenerateGlyphRunList(cacheBlob.get(), glyphCache, - *context->contextPriv().caps()->shaderCaps(), listPaint, - filteredColor, scalerContextFlags, viewMatrix, props, - glyphRunList, target->glyphPainter()); + cacheBlob->generateFromGlyphRunList( + glyphCache, *context->contextPriv().caps()->shaderCaps(), fOptions, listPaint, + filteredColor, scalerContextFlags, viewMatrix, props, glyphRunList, + target->glyphPainter()); } cacheBlob->flush(target, props, fDistanceAdjustTable.get(), listPaint, filteredColor, clip, viewMatrix, origin.x(), origin.y()); } -void GrTextContext::AppendGlyph(GrTextBlob* blob, int runIndex, +static void append_glyph(GrTextBlob* blob, int runIndex, const sk_sp& strike, const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle, SkScalar sx, SkScalar sy, @@ -580,16 +580,16 @@ void GrTextContext::AppendGlyph(GrTextBlob* blob, int runIndex, } -void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, - GrGlyphCache* glyphCache, - const GrShaderCaps& shaderCaps, - const SkPaint& paint, - const SkPMColor4f& filteredColor, - SkScalerContextFlags scalerContextFlags, - const SkMatrix& viewMatrix, - const SkSurfaceProps& props, - const SkGlyphRunList& glyphRunList, - SkGlyphRunListPainter* glyphPainter) { +void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache, + const GrShaderCaps& shaderCaps, + const GrTextContext::Options& options, + const SkPaint& paint, + const SkPMColor4f& filteredColor, + SkScalerContextFlags scalerContextFlags, + const SkMatrix& viewMatrix, + const SkSurfaceProps& props, + const SkGlyphRunList& glyphRunList, + SkGlyphRunListPainter* glyphPainter) { struct ARGBFallbackHelper { void operator ()(const SkPaint& fallbackPaint, SkSpan glyphIDs, SkSpan positions, SkScalar textScale, @@ -605,10 +605,10 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, const SkPoint* glyphPos = positions.data(); for (auto glyphID : glyphIDs) { const SkGlyph& glyph = fallbackCache->getGlyphIDMetrics(glyphID); - GrTextContext::AppendGlyph(fBlob, fRunIndex, strike, glyph, - GrGlyph::kCoverage_MaskStyle, - glyphPos->fX, glyphPos->fY, fFilteredColor, - fallbackCache.get(), textScale, needsTransform); + append_glyph(fBlob, fRunIndex, strike, glyph, + GrGlyph::kCoverage_MaskStyle, + glyphPos->fX, glyphPos->fY, fFilteredColor, + fallbackCache.get(), textScale, needsTransform); glyphPos++; } } @@ -622,44 +622,44 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, }; SkPoint origin = glyphRunList.origin(); - cacheBlob->initReusableBlob( + this->initReusableBlob( glyphRunList.paint().computeLuminanceColor(), viewMatrix, origin.x(), origin.y()); int runIndex = 0; for (const auto& glyphRun : glyphRunList) { const SkPaint& runPaint = glyphRun.paint(); - cacheBlob->push_back_run(runIndex); + this->pushBackRun(runIndex); - cacheBlob->setRunPaintFlags(runIndex, runPaint.getFlags()); + this->setRunPaintFlags(runIndex, runPaint.getFlags()); - if (CanDrawAsDistanceFields(runPaint, viewMatrix, props, - shaderCaps.supportsDistanceFieldText(), fOptions)) { + if (GrTextContext::CanDrawAsDistanceFields(runPaint, viewMatrix, props, + shaderCaps.supportsDistanceFieldText(), options)) { bool hasWCoord = viewMatrix.hasPerspective() - || fOptions.fDistanceFieldVerticesAlwaysHaveW; + || options.fDistanceFieldVerticesAlwaysHaveW; // Setup distance field runPaint and text ratio SkScalar textRatio; SkPaint distanceFieldPaint{runPaint}; SkScalerContextFlags flags; - InitDistanceFieldPaint(cacheBlob, &distanceFieldPaint, viewMatrix, - fOptions, &textRatio, &flags); - cacheBlob->setHasDistanceField(); - cacheBlob->setSubRunHasDistanceFields(runIndex, runPaint.isLCDRenderText(), + GrTextContext::InitDistanceFieldPaint(this, &distanceFieldPaint, viewMatrix, + options, &textRatio, &flags); + this->setHasDistanceField(); + this->setSubRunHasDistanceFields(runIndex, runPaint.isLCDRenderText(), runPaint.isAntiAlias(), hasWCoord); { - auto cache = cacheBlob->setupCache( + auto cache = this->setupCache( runIndex, props, flags, distanceFieldPaint, &SkMatrix::I()); sk_sp currStrike = glyphCache->getStrike(cache.get()); auto perSDF = - [cacheBlob, runIndex, &currStrike, filteredColor, cache{cache.get()}, textRatio] + [this, runIndex, &currStrike, filteredColor, cache{cache.get()}, textRatio] (const SkGlyph& glyph, SkPoint position) { if (!glyph.isEmpty()) { SkScalar sx = position.fX, sy = position.fY; - AppendGlyph(cacheBlob, runIndex, currStrike, + append_glyph(this, runIndex, currStrike, glyph, GrGlyph::kDistance_MaskStyle, sx, sy, filteredColor, cache, textRatio, true); @@ -667,19 +667,19 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, }; auto perPath = - [cacheBlob, runIndex, textRatio, cache{cache.get()}] + [this, runIndex, textRatio, cache{cache.get()}] (const SkGlyph& glyph, SkPoint position) { if (!glyph.isEmpty()) { if (const SkPath* glyphPath = cache->findPath(glyph)) { SkScalar sx = position.fX, sy = position.fY; - cacheBlob->appendPathGlyph( + this->appendPathGlyph( runIndex, *glyphPath, sx, sy, textRatio, false); } } }; - ARGBFallbackHelper argbFallback{cacheBlob, runIndex, props, scalerContextFlags, + ARGBFallbackHelper argbFallback{this, runIndex, props, scalerContextFlags, glyphCache, filteredColor}; glyphPainter->drawGlyphRunAsSDFWithARGBFallback( @@ -691,7 +691,7 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, // The glyphs are big, so use paths to draw them. // Ensure the blob is set for bitmaptext - cacheBlob->setHasBitmap(); + this->setHasBitmap(); // setup our std runPaint, in hopes of getting hits in the cache SkPaint pathPaint(runPaint); @@ -701,18 +701,18 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, pathPaint, &props, scalerContextFlags, &SkMatrix::I()); // Given a glyph that is not ARGB, draw it. - auto perPath = [textScale, runIndex, cacheBlob, &pathCache] + auto perPath = [textScale, runIndex, this, &pathCache] (const SkGlyph& glyph, SkPoint position) { if (!glyph.isEmpty()) { const SkPath* path = pathCache->findPath(glyph); if (path != nullptr) { - cacheBlob->appendPathGlyph( + this->appendPathGlyph( runIndex, *path, position.fX, position.fY, textScale, false); } } }; - ARGBFallbackHelper argbFallback{cacheBlob, runIndex, props, scalerContextFlags, + ARGBFallbackHelper argbFallback{this, runIndex, props, scalerContextFlags, glyphCache, filteredColor}; glyphPainter->drawGlyphRunAsPathWithARGBFallback( @@ -720,22 +720,22 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, std::move(perPath), std::move(argbFallback)); } else { // Ensure the blob is set for bitmaptext - cacheBlob->setHasBitmap(); + this->setHasBitmap(); - auto cache = cacheBlob->setupCache( + auto cache = this->setupCache( runIndex, props, scalerContextFlags, runPaint, &viewMatrix); sk_sp currStrike = glyphCache->getStrike(cache.get()); auto perGlyph = - [cacheBlob, runIndex, &currStrike, filteredColor, cache{cache.get()}] + [this, runIndex, &currStrike, filteredColor, cache{cache.get()}] (const SkGlyph& glyph, SkPoint mappedPt) { if (!glyph.isEmpty()) { const void* glyphImage = cache->findImage(glyph); if (glyphImage != nullptr) { SkScalar sx = SkScalarFloorToScalar(mappedPt.fX), sy = SkScalarFloorToScalar(mappedPt.fY); - AppendGlyph(cacheBlob, runIndex, currStrike, + append_glyph(this, runIndex, currStrike, glyph, GrGlyph::kCoverage_MaskStyle, sx, sy, filteredColor, cache, SK_Scalar1, false); } @@ -743,13 +743,13 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, }; auto perPath = - [cacheBlob, runIndex, cache{cache.get()}] + [this, runIndex, cache{cache.get()}] (const SkGlyph& glyph, SkPoint position) { const SkPath* glyphPath = cache->findPath(glyph); if (glyphPath != nullptr) { SkScalar sx = SkScalarFloorToScalar(position.fX), sy = SkScalarFloorToScalar(position.fY); - cacheBlob->appendPathGlyph( + this->appendPathGlyph( runIndex, *glyphPath, sx, sy, SK_Scalar1, true); } }; @@ -794,9 +794,9 @@ std::unique_ptr GrTextContext::createOp_TestingOnly(GrContext* context // Use the text and textLen below, because we don't want to mess with the paint. SkScalerContextFlags scalerContextFlags = ComputeScalerContextFlags(rtc->colorSpaceInfo()); - textContext->regenerateGlyphRunList( - blob.get(), glyphCache, *context->contextPriv().caps()->shaderCaps(), skPaint, - filteredColor, scalerContextFlags, viewMatrix, surfaceProps, + blob->generateFromGlyphRunList( + glyphCache, *context->contextPriv().caps()->shaderCaps(), textContext->fOptions, + skPaint, filteredColor, scalerContextFlags, viewMatrix, surfaceProps, glyphRunList, rtc->textTarget()->glyphPainter()); } diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h index d8b681559e..6f2b2da30e 100644 --- a/src/gpu/GrDrawingManager.h +++ b/src/gpu/GrDrawingManager.h @@ -8,6 +8,7 @@ #ifndef GrDrawingManager_DEFINED #define GrDrawingManager_DEFINED +#include "GrDeferredUpload.h" #include "GrPathRenderer.h" #include "GrPathRendererChain.h" #include "GrResourceCache.h" @@ -17,6 +18,7 @@ class GrContext; class GrCoverageCountingPathRenderer; class GrOnFlushCallbackObject; +class GrOpFlushState; class GrRenderTargetContext; class GrRenderTargetProxy; class GrSingleOWner; diff --git a/src/gpu/ops/GrAtlasTextOp.h b/src/gpu/ops/GrAtlasTextOp.h index 9229d4c797..22bdc5e3db 100644 --- a/src/gpu/ops/GrAtlasTextOp.h +++ b/src/gpu/ops/GrAtlasTextOp.h @@ -9,7 +9,7 @@ #define GrAtlasTextOp_DEFINED #include "ops/GrMeshDrawOp.h" -#include "text/GrTextContext.h" +#include "text/GrTextBlob.h" #include "text/GrDistanceFieldAdjustTable.h" #include "text/GrGlyphCache.h" diff --git a/src/gpu/text/GrTextBlob.h b/src/gpu/text/GrTextBlob.h index 2b3282f9a0..1cccaca8d2 100644 --- a/src/gpu/text/GrTextBlob.h +++ b/src/gpu/text/GrTextBlob.h @@ -12,6 +12,7 @@ #include "GrDrawOpAtlas.h" #include "GrGlyphCache.h" #include "GrTextTarget.h" +#include "text/GrTextContext.h" #include "SkDescriptor.h" #include "SkMaskFilterBase.h" #include "SkOpts.h" @@ -48,11 +49,23 @@ class SkTextBlobRunIterator; * *WARNING* If you add new fields to this struct, then you may need to to update AssertEqual */ class GrTextBlob : public SkNVRefCnt { + struct Run; public: SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrTextBlob); class VertexRegenerator; + void generateFromGlyphRunList(GrGlyphCache* glyphCache, + const GrShaderCaps& shaderCaps, + const GrTextContext::Options& options, + const SkPaint& paint, + const SkPMColor4f& filteredColor, + SkScalerContextFlags scalerContextFlags, + const SkMatrix& viewMatrix, + const SkSurfaceProps& props, + const SkGlyphRunList& glyphRunList, + SkGlyphRunListPainter* glyphPainter); + static sk_sp Make(int glyphCount, int runCount); /** @@ -121,7 +134,7 @@ public: int runCount() const { return fRunCount; } - void push_back_run(int currRun) { + void pushBackRun(int currRun) { SkASSERT(currRun < fRunCount); if (currRun > 0) { Run::SubRunInfo& newRun = fRuns[currRun].fSubRunInfo.back(); diff --git a/src/gpu/text/GrTextBlobCache.h b/src/gpu/text/GrTextBlobCache.h index a87979b761..fb991dbc95 100644 --- a/src/gpu/text/GrTextBlobCache.h +++ b/src/gpu/text/GrTextBlobCache.h @@ -8,7 +8,7 @@ #ifndef GrTextBlobCache_DEFINED #define GrTextBlobCache_DEFINED -#include "GrTextContext.h" +#include "GrTextBlob.h" #include "SkMessageBus.h" #include "SkRefCnt.h" #include "SkTArray.h" diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h index d6255e3074..9e3819bcf8 100644 --- a/src/gpu/text/GrTextContext.h +++ b/src/gpu/text/GrTextContext.h @@ -10,7 +10,6 @@ #include "GrDistanceFieldAdjustTable.h" #include "GrGeometryProcessor.h" -#include "GrTextBlob.h" #include "GrTextTarget.h" #include "SkGlyphRun.h" @@ -21,6 +20,7 @@ class GrDrawOp; class GrTextBlobCache; class SkGlyph; +class GrTextBlob; /* * Renders text using some kind of an atlas, ie BitmapText or DistanceField text @@ -76,24 +76,6 @@ private: // Determines if we need to use fake gamma (and contrast boost): static SkScalerContextFlags ComputeScalerContextFlags(const GrColorSpaceInfo&); - void regenerateGlyphRunList(GrTextBlob* bmp, - GrGlyphCache*, - const GrShaderCaps&, - const SkPaint&, - const SkPMColor4f& filteredColor, - SkScalerContextFlags scalerContextFlags, - const SkMatrix& viewMatrix, - const SkSurfaceProps&, - const SkGlyphRunList& glyphRunList, - SkGlyphRunListPainter* glyphPainter); - - static void AppendGlyph(GrTextBlob*, int runIndex, - const sk_sp&, const SkGlyph&, - GrGlyph::MaskStyle maskStyle, SkScalar sx, SkScalar sy, - const SkPMColor4f& color, SkGlyphCache*, SkScalar textRatio, - bool needsTransform); - - const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable.get(); } sk_sp fDistanceAdjustTable; diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp index 2728c76afe..d6ed10fe68 100644 --- a/tests/SkRemoteGlyphCacheTest.cpp +++ b/tests/SkRemoteGlyphCacheTest.cpp @@ -7,6 +7,7 @@ #include "Resources.h" #include "SkDraw.h" +#include "SkGlyphCache.h" #include "SkGraphics.h" #include "SkMutex.h" #include "SkRemoteGlyphCache.h"