From 3317b1b23eea691fa8633a52089c7a765a6f2240 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Thu, 9 Dec 2021 14:26:55 -0500 Subject: [PATCH] consolidate processing for sub runs multiple formats Change-Id: Ief27a4a8051485bed20e1a5312457e778cb28171 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/482007 Reviewed-by: Robert Phillips Commit-Queue: Herb Derby --- src/gpu/text/GrTextBlob.cpp | 228 ++++++++++++++---------------------- src/gpu/text/GrTextBlob.h | 7 -- 2 files changed, 89 insertions(+), 146 deletions(-) diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp index d5afd71192..5b0100ed97 100644 --- a/src/gpu/text/GrTextBlob.cpp +++ b/src/gpu/text/GrTextBlob.cpp @@ -461,7 +461,6 @@ public: static GrSubRunOwner Make(const SkZip& drawables, sk_sp&& strike, - SkScalar, GrMaskFormat format, GrTextBlob* blob, GrSubRunAllocator* alloc); @@ -529,7 +528,6 @@ DirectMaskSubRun::DirectMaskSubRun(GrMaskFormat format, GrSubRunOwner DirectMaskSubRun::Make(const SkZip& drawables, sk_sp&& strike, - SkScalar, GrMaskFormat format, GrTextBlob* blob, GrSubRunAllocator* alloc) { @@ -1382,6 +1380,33 @@ SkRect SDFTSubRun::deviceRect(const SkMatrix& drawMatrix, SkPoint drawOrigin) co GrAtlasSubRun* SDFTSubRun::testingOnly_atlasSubRun() { return this; } + +template +void add_multi_mask_format( + AddSingleMaskFormat addSingleMaskFormat, + const SkZip& drawables, + sk_sp&& strike) { + if (drawables.empty()) { return; } + + auto glyphSpan = drawables.get<0>(); + SkGlyph* glyph = glyphSpan[0]; + GrMaskFormat format = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); + size_t startIndex = 0; + for (size_t i = 1; i < drawables.size(); i++) { + glyph = glyphSpan[i]; + GrMaskFormat nextFormat = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); + if (format != nextFormat) { + auto glyphsWithSameFormat = drawables.subspan(startIndex, i - startIndex); + // Take a ref on the strike. This should rarely happen. + addSingleMaskFormat(glyphsWithSameFormat, format, sk_sp(strike)); + format = nextFormat; + startIndex = i; + } + } + auto glyphsWithSameFormat = drawables.last(drawables.size() - startIndex); + addSingleMaskFormat(glyphsWithSameFormat, format, std::move(strike)); +} + } // namespace // -- GrTextBlob::Key ------------------------------------------------------------------------------ @@ -1601,45 +1626,6 @@ bool GrTextBlob::canReuse(const SkPaint& paint, const SkMatrix& positionMatrix) const GrTextBlob::Key& GrTextBlob::key() const { return fKey; } size_t GrTextBlob::size() const { return fSize; } -template -void GrTextBlob::addMultiMaskFormat( - AddSingleMaskFormat addSingle, - const SkZip& drawables, - sk_sp&& strike, - SkScalar strikeToSourceScale) { - if (drawables.empty()) { return; } - - auto addSameFormat = [&](const SkZip& drawable, - GrMaskFormat format, - sk_sp&& runStrike) { - GrSubRunOwner subRun = addSingle( - drawable, std::move(runStrike), strikeToSourceScale, format, this, &fAlloc); - if (subRun != nullptr) { - fSubRunList.append(std::move(subRun)); - } else { - fSomeGlyphsExcluded = true; - } - }; - - auto glyphSpan = drawables.get<0>(); - SkGlyph* glyph = glyphSpan[0]; - GrMaskFormat format = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); - size_t startIndex = 0; - for (size_t i = 1; i < drawables.size(); i++) { - glyph = glyphSpan[i]; - GrMaskFormat nextFormat = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); - if (format != nextFormat) { - auto sameFormat = drawables.subspan(startIndex, i - startIndex); - // Take a ref on the strike. This should rarely happen. - addSameFormat(sameFormat, format, sk_sp(strike)); - format = nextFormat; - startIndex = i; - } - } - auto sameFormat = drawables.last(drawables.size() - startIndex); - addSameFormat(sameFormat, format, std::move(strike)); -} - GrTextBlob::GrTextBlob(int allocSize, const SkMatrix& positionMatrix, SkColor initialLuminance) @@ -1648,10 +1634,21 @@ GrTextBlob::GrTextBlob(int allocSize, , fInitialPositionMatrix{positionMatrix} , fInitialLuminance{initialLuminance} { } -void GrTextBlob::processDeviceMasks(const SkZip& drawables, - sk_sp&& strike) { +void GrTextBlob::processDeviceMasks( + const SkZip& drawables, sk_sp&& strike) { SkASSERT(strike != nullptr); - this->addMultiMaskFormat(DirectMaskSubRun::Make, drawables, std::move(strike), 1); + auto addGlyphsWithSameFormat = [&] (const SkZip& drawable, + GrMaskFormat format, + sk_sp&& runStrike) { + GrSubRunOwner subRun = DirectMaskSubRun::Make( + drawable, std::move(runStrike), format, this, &fAlloc); + if (subRun != nullptr) { + fSubRunList.append(std::move(subRun)); + } else { + fSomeGlyphsExcluded = true; + } + }; + add_multi_mask_format(addGlyphsWithSameFormat, drawables, std::move(strike)); } void GrTextBlob::processSourcePaths(const SkZip& drawables, @@ -1679,8 +1676,18 @@ void GrTextBlob::processSourceSDFT(const SkZip& drawabl void GrTextBlob::processSourceMasks(const SkZip& drawables, sk_sp&& strike, SkScalar strikeToSourceScale) { - this->addMultiMaskFormat( - TransformedMaskSubRun::Make, drawables, std::move(strike), strikeToSourceScale); + auto addGlyphsWithSameFormat = [&] (const SkZip& drawable, + GrMaskFormat format, + sk_sp&& runStrike) { + GrSubRunOwner subRun = TransformedMaskSubRun::Make( + drawable, std::move(runStrike), strikeToSourceScale, format, this, &fAlloc); + if (subRun != nullptr) { + fSubRunList.append(std::move(subRun)); + } else { + fSomeGlyphsExcluded = true; + } + }; + add_multi_mask_format(addGlyphsWithSameFormat, drawables, std::move(strike)); } // ----------------------------- Begin no cache implementation ------------------------------------- @@ -2379,56 +2386,25 @@ GrSubRunNoCachePainter::GrSubRunNoCachePainter(skgpu::v1::SurfaceDrawContext* sd void GrSubRunNoCachePainter::processDeviceMasks( const SkZip& drawables, sk_sp&& strike) { - if (drawables.empty()) { return; } + auto addGlyphsWithSameFormat = [&] (const SkZip& drawable, + GrMaskFormat format, + sk_sp&& runStrike) { + this->draw(DirectMaskSubRunNoCache::Make(drawable, std::move(runStrike), format, fAlloc)); + }; - auto glyphSpan = drawables.get<0>(); - SkGlyph* glyph = glyphSpan[0]; - GrMaskFormat format = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); - size_t startIndex = 0; - for (size_t i = 1; i < drawables.size(); i++) { - glyph = glyphSpan[i]; - GrMaskFormat nextFormat = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); - if (format != nextFormat) { - auto sameFormat = drawables.subspan(startIndex, i - startIndex); - // Take an extra ref on the strike. This should rarely happen. - this->draw( - DirectMaskSubRunNoCache::Make(sameFormat, sk_sp(strike), format, fAlloc)); - format = nextFormat; - startIndex = i; - } - } - auto sameFormat = drawables.last(drawables.size() - startIndex); - this->draw(DirectMaskSubRunNoCache::Make(sameFormat, std::move(strike), format, fAlloc)); + add_multi_mask_format(addGlyphsWithSameFormat, drawables, std::move(strike)); } void GrSubRunNoCachePainter::processSourceMasks(const SkZip& drawables, sk_sp&& strike, SkScalar strikeToSourceScale) { - if (drawables.empty()) { - return; - } - - auto glyphSpan = drawables.get<0>(); - SkGlyph* glyph = glyphSpan[0]; - GrMaskFormat format = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); - size_t startIndex = 0; - for (size_t i = 1; i < drawables.size(); i++) { - glyph = glyphSpan[i]; - GrMaskFormat nextFormat = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); - if (format != nextFormat) { - auto sameFormat = drawables.subspan(startIndex, i - startIndex); - this->draw( - // Add an extra ref to the strike. This should rarely happen. - TransformedMaskSubRunNoCache::Make( - sameFormat, sk_sp(strike), strikeToSourceScale, format, fAlloc)); - format = nextFormat; - startIndex = i; - } - } - auto sameFormat = drawables.last(drawables.size() - startIndex); - this->draw( - TransformedMaskSubRunNoCache::Make( - sameFormat, std::move(strike), strikeToSourceScale, format, fAlloc)); + auto addGlyphsWithSameFormat = [&] (const SkZip& drawable, + GrMaskFormat format, + sk_sp&& runStrike) { + this->draw(TransformedMaskSubRunNoCache::Make( + drawable, std::move(runStrike), strikeToSourceScale, format, fAlloc)); + }; + add_multi_mask_format(addGlyphsWithSameFormat, drawables, std::move(strike)); } void GrSubRunNoCachePainter::processSourcePaths(const SkZip& drawables, @@ -2600,13 +2576,6 @@ public: void* operator new(size_t, void* p) { return p; } private: - template - void addMultiMaskFormat( - AddSingleMaskFormat addSingle, - const SkZip& drawables, - sk_sp&& strike, - SkScalar strikeToSourceScale); - const SkRect fSourceBounds; const SkPaint fPaint; const SkMatrix fInitialPositionMatrix; @@ -2626,43 +2595,6 @@ Slug::Slug(SkRect sourceBounds, , fOrigin{origin} , fAlloc {SkTAddOffset(this, sizeof(Slug)), allocSize, allocSize/2} { } -template -void Slug::addMultiMaskFormat( - AddSingleMaskFormat addSingle, - const SkZip& drawables, - sk_sp&& strike, - SkScalar strikeToSourceScale) { - if (drawables.empty()) { return; } - - auto addSameFormat = [&](const SkZip& drawable, - GrMaskFormat format, - sk_sp&& runStrike) { - SlugSubRunOwner subRun = addSingle( - this, drawable, std::move(runStrike), strikeToSourceScale, format, &fAlloc); - if (subRun != nullptr) { - fSubRuns.append(std::move(subRun)); - } - }; - - auto glyphSpan = drawables.get<0>(); - SkGlyph* glyph = glyphSpan[0]; - GrMaskFormat format = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); - size_t startIndex = 0; - for (size_t i = 1; i < drawables.size(); i++) { - glyph = glyphSpan[i]; - GrMaskFormat nextFormat = GrGlyph::FormatFromSkGlyph(glyph->maskFormat()); - if (format != nextFormat) { - auto sameFormat = drawables.subspan(startIndex, i - startIndex); - // Take a ref on the strike. This should rarely happen. - addSameFormat(sameFormat, format, sk_sp(strike)); - format = nextFormat; - startIndex = i; - } - } - auto sameFormat = drawables.last(drawables.size() - startIndex); - addSameFormat(sameFormat, format, std::move(strike)); -} - void Slug::surfaceDraw(const GrClip* clip, const SkMatrixProvider& viewMatrix, skgpu::v1::SurfaceDrawContext* sdc) { for (const SlugSubRun& subRun : fSubRuns) { @@ -2684,7 +2616,6 @@ public: static SlugSubRunOwner Make(Slug* slug, const SkZip& drawables, sk_sp&& strike, - SkScalar strikeToSourceScale, GrMaskFormat format, GrSubRunAllocator* alloc); @@ -2754,7 +2685,6 @@ DirectMaskSubRunSlug::DirectMaskSubRunSlug(Slug* slug, SlugSubRunOwner DirectMaskSubRunSlug::Make(Slug* slug, const SkZip& drawables, sk_sp&& strike, - SkScalar strikeToSourceScale, GrMaskFormat format, GrSubRunAllocator* alloc) { DevicePosition* glyphLeftTop = alloc->makePODArray(drawables.size()); @@ -3047,7 +2977,17 @@ DirectMaskSubRunSlug::deviceRectAndCheckTransform(const SkMatrix& positionMatrix void Slug::processDeviceMasks( const SkZip& drawables, sk_sp&& strike) { - this->addMultiMaskFormat(DirectMaskSubRunSlug::Make, drawables, std::move(strike), 1); + auto addGlyphsWithSameFormat = [&] (const SkZip& drawable, + GrMaskFormat format, + sk_sp&& runStrike) { + SlugSubRunOwner subRun = DirectMaskSubRunSlug::Make( + this, drawable, std::move(runStrike), format, &fAlloc); + if (subRun != nullptr) { + fSubRuns.append(std::move(subRun)); + } + }; + + add_multi_mask_format(addGlyphsWithSameFormat, drawables, std::move(strike)); } sk_sp Slug::Make(const SkMatrixProvider& viewMatrix, @@ -3691,8 +3631,18 @@ SkRect TransformedMaskSubRunSlug::deviceRect(const SkMatrix& drawMatrix, SkPoint void Slug::processSourceMasks(const SkZip& drawables, sk_sp&& strike, SkScalar strikeToSourceScale) { - this->addMultiMaskFormat( - TransformedMaskSubRunSlug::Make, drawables, std::move(strike), strikeToSourceScale); + + auto addGlyphsWithSameFormat = [&] (const SkZip& drawable, + GrMaskFormat format, + sk_sp&& runStrike) { + SlugSubRunOwner subRun = TransformedMaskSubRunSlug::Make( + this, drawable, std::move(runStrike), strikeToSourceScale, format, &fAlloc); + if (subRun != nullptr) { + fSubRuns.append(std::move(subRun)); + } + }; + + add_multi_mask_format(addGlyphsWithSameFormat, drawables, std::move(strike)); } } // namespace diff --git a/src/gpu/text/GrTextBlob.h b/src/gpu/text/GrTextBlob.h index 1d34d54523..a4909fd858 100644 --- a/src/gpu/text/GrTextBlob.h +++ b/src/gpu/text/GrTextBlob.h @@ -250,13 +250,6 @@ public: private: GrTextBlob(int allocSize, const SkMatrix& positionMatrix, SkColor initialLuminance); - template - void addMultiMaskFormat( - AddSingleMaskFormat addSingle, - const SkZip& drawables, - sk_sp&& strike, - SkScalar strikeToSourceScale); - // Methods to satisfy SkGlyphRunPainterInterface void processDeviceMasks(const SkZip& drawables, sk_sp&& strike) override;