consolidate processing for sub runs multiple formats

Change-Id: Ief27a4a8051485bed20e1a5312457e778cb28171
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/482007
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2021-12-09 14:26:55 -05:00 committed by SkCQ
parent e4f148f09f
commit 3317b1b23e
2 changed files with 89 additions and 146 deletions

View File

@ -461,7 +461,6 @@ public:
static GrSubRunOwner Make(const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike,
SkScalar,
GrMaskFormat format,
GrTextBlob* blob,
GrSubRunAllocator* alloc);
@ -529,7 +528,6 @@ DirectMaskSubRun::DirectMaskSubRun(GrMaskFormat format,
GrSubRunOwner DirectMaskSubRun::Make(const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& 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<typename AddSingleMaskFormat>
void add_multi_mask_format(
AddSingleMaskFormat addSingleMaskFormat,
const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& 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<SkStrike>(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<typename AddSingleMaskFormat>
void GrTextBlob::addMultiMaskFormat(
AddSingleMaskFormat addSingle,
const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale) {
if (drawables.empty()) { return; }
auto addSameFormat = [&](const SkZip<SkGlyphVariant, SkPoint>& drawable,
GrMaskFormat format,
sk_sp<SkStrike>&& 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<SkStrike>(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<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike) {
void GrTextBlob::processDeviceMasks(
const SkZip<SkGlyphVariant, SkPoint>& drawables, sk_sp<SkStrike>&& strike) {
SkASSERT(strike != nullptr);
this->addMultiMaskFormat(DirectMaskSubRun::Make, drawables, std::move(strike), 1);
auto addGlyphsWithSameFormat = [&] (const SkZip<SkGlyphVariant, SkPoint>& drawable,
GrMaskFormat format,
sk_sp<SkStrike>&& 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<SkGlyphVariant, SkPoint>& drawables,
@ -1679,8 +1676,18 @@ void GrTextBlob::processSourceSDFT(const SkZip<SkGlyphVariant, SkPoint>& drawabl
void GrTextBlob::processSourceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale) {
this->addMultiMaskFormat(
TransformedMaskSubRun::Make, drawables, std::move(strike), strikeToSourceScale);
auto addGlyphsWithSameFormat = [&] (const SkZip<SkGlyphVariant, SkPoint>& drawable,
GrMaskFormat format,
sk_sp<SkStrike>&& 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<SkGlyphVariant, SkPoint>& drawables, sk_sp<SkStrike>&& strike) {
if (drawables.empty()) { return; }
auto addGlyphsWithSameFormat = [&] (const SkZip<SkGlyphVariant, SkPoint>& drawable,
GrMaskFormat format,
sk_sp<SkStrike>&& 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<SkStrike>(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<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& 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<SkStrike>(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<SkGlyphVariant, SkPoint>& drawable,
GrMaskFormat format,
sk_sp<SkStrike>&& 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<SkGlyphVariant, SkPoint>& drawables,
@ -2600,13 +2576,6 @@ public:
void* operator new(size_t, void* p) { return p; }
private:
template<typename AddSingleMaskFormat>
void addMultiMaskFormat(
AddSingleMaskFormat addSingle,
const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale);
const SkRect fSourceBounds;
const SkPaint fPaint;
const SkMatrix fInitialPositionMatrix;
@ -2626,43 +2595,6 @@ Slug::Slug(SkRect sourceBounds,
, fOrigin{origin}
, fAlloc {SkTAddOffset<char>(this, sizeof(Slug)), allocSize, allocSize/2} { }
template<typename AddSingleMaskFormat>
void Slug::addMultiMaskFormat(
AddSingleMaskFormat addSingle,
const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale) {
if (drawables.empty()) { return; }
auto addSameFormat = [&](const SkZip<SkGlyphVariant, SkPoint>& drawable,
GrMaskFormat format,
sk_sp<SkStrike>&& 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<SkStrike>(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<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale,
GrMaskFormat format,
GrSubRunAllocator* alloc);
@ -2754,7 +2685,6 @@ DirectMaskSubRunSlug::DirectMaskSubRunSlug(Slug* slug,
SlugSubRunOwner DirectMaskSubRunSlug::Make(Slug* slug,
const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale,
GrMaskFormat format,
GrSubRunAllocator* alloc) {
DevicePosition* glyphLeftTop = alloc->makePODArray<DevicePosition>(drawables.size());
@ -3047,7 +2977,17 @@ DirectMaskSubRunSlug::deviceRectAndCheckTransform(const SkMatrix& positionMatrix
void Slug::processDeviceMasks(
const SkZip<SkGlyphVariant, SkPoint>& drawables, sk_sp<SkStrike>&& strike) {
this->addMultiMaskFormat(DirectMaskSubRunSlug::Make, drawables, std::move(strike), 1);
auto addGlyphsWithSameFormat = [&] (const SkZip<SkGlyphVariant, SkPoint>& drawable,
GrMaskFormat format,
sk_sp<SkStrike>&& 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> Slug::Make(const SkMatrixProvider& viewMatrix,
@ -3691,8 +3631,18 @@ SkRect TransformedMaskSubRunSlug::deviceRect(const SkMatrix& drawMatrix, SkPoint
void Slug::processSourceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale) {
this->addMultiMaskFormat(
TransformedMaskSubRunSlug::Make, drawables, std::move(strike), strikeToSourceScale);
auto addGlyphsWithSameFormat = [&] (const SkZip<SkGlyphVariant, SkPoint>& drawable,
GrMaskFormat format,
sk_sp<SkStrike>&& 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

View File

@ -250,13 +250,6 @@ public:
private:
GrTextBlob(int allocSize, const SkMatrix& positionMatrix, SkColor initialLuminance);
template<typename AddSingleMaskFormat>
void addMultiMaskFormat(
AddSingleMaskFormat addSingle,
const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike,
SkScalar strikeToSourceScale);
// Methods to satisfy SkGlyphRunPainterInterface
void processDeviceMasks(const SkZip<SkGlyphVariant, SkPoint>& drawables,
sk_sp<SkStrike>&& strike) override;