From 8c748076c15a504901a0abb4b8255ff11d508beb Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Mon, 31 Jan 2022 13:57:50 -0500 Subject: [PATCH] use TransformedMaskSubRun in Slug Change-Id: I3d59b646a2e2fcd919d23077ba542a81af5f0303 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/502302 Reviewed-by: Robert Phillips Commit-Queue: Herb Derby --- src/gpu/text/GrTextBlob.cpp | 199 ++---------------------------------- 1 file changed, 7 insertions(+), 192 deletions(-) diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp index 179d4f9140..c03c168be9 100644 --- a/src/gpu/text/GrTextBlob.cpp +++ b/src/gpu/text/GrTextBlob.cpp @@ -1072,11 +1072,11 @@ public: SkSpan vertexData, GlyphVector&& glyphs); - static GrSubRunOwner Make(const SkZip& drawables, + static GrSubRunOwner Make(GrTextReferenceFrame* referenceFrame, + const SkZip& drawables, sk_sp&& strike, SkScalar strikeToSourceScale, GrMaskFormat format, - GrTextBlob* blob, GrSubRunAllocator* alloc); void draw(SkCanvas*, @@ -1142,11 +1142,11 @@ TransformedMaskSubRun::TransformedMaskSubRun(GrTextReferenceFrame* referenceFram , fVertexData{vertexData} , fGlyphs{std::move(glyphs)} { } -GrSubRunOwner TransformedMaskSubRun::Make(const SkZip& drawables, +GrSubRunOwner TransformedMaskSubRun::Make(GrTextReferenceFrame* referenceFrame, + const SkZip& drawables, sk_sp&& strike, SkScalar strikeToSourceScale, GrMaskFormat format, - GrTextBlob* blob, GrSubRunAllocator* alloc) { SkRect bounds = SkRectPriv::MakeLargestInverted(); @@ -1167,7 +1167,7 @@ GrSubRunOwner TransformedMaskSubRun::Make(const SkZip& }); return alloc->makeUnique( - blob, format, strikeToSourceScale, bounds, vertexData, + referenceFrame, format, strikeToSourceScale, bounds, vertexData, GlyphVector::Make(std::move(strike), drawables.get<0>(), alloc)); } @@ -1870,7 +1870,7 @@ void GrTextBlob::processSourceMasks(const SkZip& drawab GrMaskFormat format, sk_sp&& runStrike) { GrSubRunOwner subRun = TransformedMaskSubRun::Make( - drawable, std::move(runStrike), strikeToSourceScale, format, this, &fAlloc); + this, drawable, std::move(runStrike), strikeToSourceScale, format, &fAlloc); if (subRun != nullptr) { fSubRunList.append(std::move(subRun)); } else { @@ -3334,191 +3334,6 @@ void Slug::processSourceSDFT(const SkZip& drawables, this, drawables, runFont, std::move(strike), strikeToSourceScale, &fAlloc)); } -class TransformedMaskSubRunSlug final : public GrSubRun, public GrAtlasSubRun { -public: - using VertexData = TransformedMaskVertexFiller::PositionAndExtent; - - TransformedMaskSubRunSlug(GrTextReferenceFrame* referenceFrame, - GrMaskFormat format, - SkScalar strikeToSourceScale, - const SkRect& bounds, - SkSpan vertexData, - GlyphVector&& glyphs); - - static GrSubRunOwner Make(Slug* slug, - const SkZip& drawables, - sk_sp&& strike, - SkScalar strikeToSourceScale, - GrMaskFormat format, - GrSubRunAllocator* alloc); - - void draw(SkCanvas*, - const GrClip*, - const SkMatrixProvider& viewMatrix, - SkPoint drawOrigin, - const SkPaint&, - skgpu::v1::SurfaceDrawContext*) const override; - - std::tuple - makeAtlasTextOp(const GrClip* clip, - const SkMatrixProvider& viewMatrix, - SkPoint drawOrigin, - const SkPaint& paint, - skgpu::v1::SurfaceDrawContext* sdc, - GrAtlasSubRunOwner subRunOwner) const override; - - void testingOnly_packedGlyphIDToGrGlyph(GrStrikeCache *cache) const override; - - std::tuple regenerateAtlas(int begin, int end, GrMeshDrawTarget*) const override; - - void fillVertexData(void* vertexDst, int offset, int count, - GrColor color, - const SkMatrix& drawMatrix, SkPoint drawOrigin, - SkIRect clip) const override; - - size_t vertexStride(const SkMatrix& drawMatrix) const override; - int glyphCount() const override; - -private: - // The rectangle that surrounds all the glyph bounding boxes in device space. - SkRect deviceRect(const SkMatrix& drawMatrix, SkPoint drawOrigin) const; - const TransformedMaskVertexFiller fVertexFiller; - GrTextReferenceFrame* const fReferenceFrame; - - // The bounds in source space. The bounds are the joined rectangles of all the glyphs. - const SkRect fVertexBounds; - const SkSpan fVertexData; - - // The regenerateAtlas method mutates fGlyphs. It should be called from onPrepare which must - // be single threaded. - mutable GlyphVector fGlyphs; -}; - -TransformedMaskSubRunSlug::TransformedMaskSubRunSlug( - GrTextReferenceFrame* referenceFrame, - GrMaskFormat format, - SkScalar strikeToSourceScale, - const SkRect& bounds, - SkSpan vertexData, - GlyphVector&& glyphs) - : fVertexFiller{format, 0, strikeToSourceScale} - , fReferenceFrame{referenceFrame} - , fVertexBounds{bounds} - , fVertexData{vertexData} - , fGlyphs{std::move(glyphs)} { } - -GrSubRunOwner TransformedMaskSubRunSlug::Make(Slug* slug, - const SkZip& drawables, - sk_sp&& strike, - SkScalar strikeToSourceScale, - GrMaskFormat format, - GrSubRunAllocator* alloc) { - SkRect bounds = SkRectPriv::MakeLargestInverted(); - - SkSpan vertexData = alloc->makePODArray( - drawables, - [&](auto e) { - auto [variant, pos] = e; - SkGlyph* skGlyph = variant; - int16_t l = skGlyph->left(), - t = skGlyph->top(), - r = l + skGlyph->width(), - b = t + skGlyph->height(); - SkPoint lt = SkPoint::Make(l, t) * strikeToSourceScale + pos, - rb = SkPoint::Make(r, b) * strikeToSourceScale + pos; - - bounds.joinPossiblyEmptyRect(SkRect::MakeLTRB(lt.x(), lt.y(), rb.x(), rb.y())); - return VertexData{pos, {l, t, r, b}}; - }); - - return alloc->makeUnique( - slug, format, strikeToSourceScale, bounds, vertexData, - GlyphVector::Make(std::move(strike), drawables.get<0>(), alloc)); -} - -void TransformedMaskSubRunSlug::draw(SkCanvas*, - const GrClip* clip, - const SkMatrixProvider& viewMatrix, - SkPoint drawOrigin, - const SkPaint& paint, - skgpu::v1::SurfaceDrawContext* sdc) const { - auto[drawingClip, op] = this->makeAtlasTextOp( - clip, viewMatrix, drawOrigin, paint, sdc, nullptr); - if (op != nullptr) { - sdc->addDrawOp(drawingClip, std::move(op)); - } -} - -std::tuple -TransformedMaskSubRunSlug::makeAtlasTextOp(const GrClip* clip, - const SkMatrixProvider& viewMatrix, - SkPoint drawOrigin, - const SkPaint& paint, - skgpu::v1::SurfaceDrawContext* sdc, - GrAtlasSubRunOwner) const { - SkASSERT(this->glyphCount() != 0); - - const SkMatrix& drawMatrix = viewMatrix.localToDevice(); - - GrPaint grPaint; - SkPMColor4f drawingColor = calculate_colors( - sdc, paint, viewMatrix, fVertexFiller.grMaskType(), &grPaint); - - auto geometry = AtlasTextOp::Geometry::MakeForBlob(*this, - drawMatrix, - drawOrigin, - SkIRect::MakeEmpty(), - sk_ref_sp(fReferenceFrame), - drawingColor, - sdc->arenaAlloc()); - - GrRecordingContext* const rContext = sdc->recordingContext(); - GrOp::Owner op = GrOp::Make(rContext, - fVertexFiller.opMaskType(), - true, - this->glyphCount(), - this->deviceRect(drawMatrix, drawOrigin), - geometry, - std::move(grPaint)); - return {clip, std::move(op)}; -} - -void TransformedMaskSubRunSlug::testingOnly_packedGlyphIDToGrGlyph(GrStrikeCache *cache) const { - fGlyphs.packedGlyphIDToGrGlyph(cache); -} - -std::tuple TransformedMaskSubRunSlug::regenerateAtlas( - int begin, int end, GrMeshDrawTarget* target) const { - return fGlyphs.regenerateAtlas(begin, end, fVertexFiller.grMaskType(), 1, target, true); -} - -void TransformedMaskSubRunSlug::fillVertexData(void* vertexDst, int offset, int count, - GrColor color, - const SkMatrix& drawMatrix, SkPoint drawOrigin, - SkIRect clip) const { - const SkMatrix positionMatrix = position_matrix(drawMatrix, drawOrigin); - fVertexFiller.fillVertexData(fGlyphs.glyphs().subspan(offset, count), - fVertexData.subspan(offset, count), - color, - positionMatrix, - clip, - vertexDst); -} - -size_t TransformedMaskSubRunSlug::vertexStride(const SkMatrix& drawMatrix) const { - return fVertexFiller.vertexStride(drawMatrix); -} - -int TransformedMaskSubRunSlug::glyphCount() const { - return SkCount(fVertexData); -} - -SkRect TransformedMaskSubRunSlug::deviceRect(const SkMatrix& drawMatrix, SkPoint drawOrigin) const { - SkRect outBounds = fVertexBounds; - outBounds.offset(drawOrigin); - return drawMatrix.mapRect(outBounds); -} - void Slug::processSourceMasks(const SkZip& drawables, sk_sp&& strike, SkScalar strikeToSourceScale) { @@ -3526,7 +3341,7 @@ void Slug::processSourceMasks(const SkZip& drawables, auto addGlyphsWithSameFormat = [&] (const SkZip& drawable, GrMaskFormat format, sk_sp&& runStrike) { - GrSubRunOwner subRun = TransformedMaskSubRunSlug::Make( + GrSubRunOwner subRun = TransformedMaskSubRun::Make( this, drawable, std::move(runStrike), strikeToSourceScale, format, &fAlloc); if (subRun != nullptr) { fSubRuns.append(std::move(subRun));