use SDFTSubRun for Slugs; remove SDFTSubRunSlug

Change-Id: Ie4b64393df378821d55f0eb96f52aff26734911c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/502781
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2022-02-01 16:22:21 -05:00 committed by SkCQ
parent eccf8a03ad
commit 904d26fab4

View File

@ -3073,236 +3073,13 @@ void Slug::processSourcePaths(const SkZip<SkGlyphVariant,
drawables, has_some_antialiasing(runFont), strikeToSourceScale, &fAlloc));
}
// -- SDFTSubRunSlug -------------------------------------------------------------------------------
class SDFTSubRunSlug final : public GrSubRun, public GrAtlasSubRun {
public:
struct VertexData {
const SkPoint pos;
// The rectangle of the glyphs in strike space.
GrIRect16 rect;
};
SDFTSubRunSlug(Slug* slug,
GrMaskFormat format,
SkScalar strikeToSource,
SkRect vertexBounds,
SkSpan<const VertexData> vertexData,
GlyphVector&& glyphs,
bool useLCDText,
bool antiAliased);
static GrSubRunOwner Make(Slug* slug,
const SkZip<SkGlyphVariant, SkPoint>& drawables,
const SkFont& runFont,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale,
GrSubRunAllocator* alloc);
void draw(SkCanvas*,
const GrClip* clip,
const SkMatrixProvider& viewMatrix,
SkPoint drawOrigin,
const SkPaint& paint,
skgpu::v1::SurfaceDrawContext* sdc) const override;
std::tuple<const GrClip*, GrOp::Owner>
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<bool, int> 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:
Slug* const fSlug;
// The rectangle that surrounds all the glyph bounding boxes in device space.
SkRect deviceRect(const SkMatrix& drawMatrix, SkPoint drawOrigin) const;
const GrMaskFormat fMaskFormat;
// The scale factor between the strike size, and the source size.
const SkScalar fStrikeToSourceScale;
// The bounds in source space. The bounds are the joined rectangles of all the glyphs.
const SkRect fVertexBounds;
const SkSpan<const VertexData> fVertexData;
// The regenerateAtlas method mutates fGlyphs. It should be called from onPrepare which must
// be single threaded.
mutable GlyphVector fGlyphs;
const bool fUseLCDText;
const bool fAntiAliased;
};
SDFTSubRunSlug::SDFTSubRunSlug(Slug* slug,
GrMaskFormat format,
SkScalar strikeToSource,
SkRect vertexBounds,
SkSpan<const VertexData> vertexData,
GlyphVector&& glyphs,
bool useLCDText,
bool antiAliased)
: fSlug{slug}
, fMaskFormat{format}
, fStrikeToSourceScale{strikeToSource}
, fVertexBounds{vertexBounds}
, fVertexData{vertexData}
, fGlyphs{std::move(glyphs)}
, fUseLCDText{useLCDText}
, fAntiAliased{antiAliased} {}
GrSubRunOwner SDFTSubRunSlug::Make(Slug* slug,
const SkZip<SkGlyphVariant, SkPoint>& drawables,
const SkFont& runFont,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale,
GrSubRunAllocator* alloc) {
SkRect bounds = SkRectPriv::MakeLargestInverted();
auto mapper = [&](const auto& d) {
auto& [variant, pos] = d;
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}};
};
SkSpan<VertexData> vertexData = alloc->makePODArray<VertexData>(drawables, mapper);
return alloc->makeUnique<SDFTSubRunSlug>(
slug,
kA8_GrMaskFormat,
strikeToSourceScale,
bounds,
vertexData,
GlyphVector::Make(std::move(strike), drawables.get<0>(), alloc),
runFont.getEdging() == SkFont::Edging::kSubpixelAntiAlias,
has_some_antialiasing(runFont));
}
void SDFTSubRunSlug::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<const GrClip*, GrOp::Owner >
SDFTSubRunSlug::makeAtlasTextOp(const GrClip* clip,
const SkMatrixProvider& viewMatrix,
SkPoint drawOrigin,
const SkPaint& paint,
skgpu::v1::SurfaceDrawContext* sdc,
GrAtlasSubRunOwner subRunOwner) const {
SkASSERT(this->glyphCount() != 0);
SkASSERT(!viewMatrix.localToDevice().hasPerspective());
const SkMatrix& drawMatrix = viewMatrix.localToDevice();
GrPaint grPaint;
SkPMColor4f drawingColor = calculate_colors(sdc, paint, viewMatrix, fMaskFormat, &grPaint);
auto [maskType, DFGPFlags, useGammaCorrectDistanceTable] =
calculate_sdf_parameters(*sdc, drawMatrix, fUseLCDText, fAntiAliased);
auto geometry = AtlasTextOp::Geometry::MakeForBlob(*this,
drawMatrix,
drawOrigin,
SkIRect::MakeEmpty(),
sk_ref_sp<Slug>(fSlug),
drawingColor,
sdc->arenaAlloc());
GrRecordingContext* const rContext = sdc->recordingContext();
GrOp::Owner op = GrOp::Make<AtlasTextOp>(rContext,
maskType,
true,
this->glyphCount(),
this->deviceRect(drawMatrix, drawOrigin),
SkPaintPriv::ComputeLuminanceColor(paint),
useGammaCorrectDistanceTable,
DFGPFlags,
geometry,
std::move(grPaint));
return {clip, std::move(op)};
}
void SDFTSubRunSlug::testingOnly_packedGlyphIDToGrGlyph(GrStrikeCache *cache) const {
fGlyphs.packedGlyphIDToGrGlyph(cache);
}
std::tuple<bool, int> SDFTSubRunSlug::regenerateAtlas(
int begin, int end, GrMeshDrawTarget *target) const {
return fGlyphs.regenerateAtlas(begin, end, fMaskFormat, SK_DistanceFieldInset, target);
}
size_t SDFTSubRunSlug::vertexStride(const SkMatrix& drawMatrix) const {
return sizeof(Mask2DVertex);
}
void SDFTSubRunSlug::fillVertexData(void* vertexDst, int offset, int count,
GrColor color,
const SkMatrix& drawMatrix, SkPoint drawOrigin,
SkIRect clip) const {
using Quad = Mask2DVertex[4];
const SkMatrix positionMatrix = position_matrix(drawMatrix, drawOrigin);
SkASSERT(sizeof(Mask2DVertex) == this->vertexStride(positionMatrix));
fill_transformed_vertices_2D(
SkMakeZip((Quad*)vertexDst,
fGlyphs.glyphs().subspan(offset, count),
fVertexData.subspan(offset, count)),
SK_DistanceFieldInset,
fStrikeToSourceScale,
color,
positionMatrix);
}
int SDFTSubRunSlug::glyphCount() const {
return SkCount(fVertexData);
}
SkRect SDFTSubRunSlug::deviceRect(const SkMatrix& drawMatrix, SkPoint drawOrigin) const {
SkRect outBounds = fVertexBounds;
outBounds.offset(drawOrigin);
return drawMatrix.mapRect(outBounds);
}
void Slug::processSourceSDFT(const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale,
const SkFont& runFont,
const GrSDFTMatrixRange&) {
fSubRuns.append(SDFTSubRunSlug::Make(
this, drawables, runFont, std::move(strike), strikeToSourceScale, &fAlloc));
const GrSDFTMatrixRange& matrixRange) {
fSubRuns.append(SDFTSubRun::Make(
this, drawables, runFont, std::move(strike), strikeToSourceScale, matrixRange, &fAlloc));
}
void Slug::processSourceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables,