Fix Op tests when default typeface is empty.

While testing on Linux with a configuration like

skia_enable_fontmgr_custom_directory=false
skia_enable_fontmgr_custom_embedded=false
skia_enable_fontmgr_custom_empty=true
skia_enable_gpu=true
skia_use_fontconfig=false
skia_use_freetype=true
skia_use_system_freetype2=false

the default typeface will be an empty typeface with no glyphs. This of
course leads to many test failures, which is fine.

However, this also leads to crashes when testing GPU Ops since the Op
factories may return nullptr to indicate no-op but the callers of those
factories currently do not expect nullptr or handle it as a no-op.

Change the callers of Op factories to treat nullptr as no-op.

Change-Id: I9eb1dfca4a8a9066a9cfb4c902d1f52d07763667
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301586
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2020-07-09 16:19:35 -04:00 committed by Skia Commit-Bot
parent 7a96c2a6bb
commit 525e87682c
3 changed files with 12 additions and 5 deletions

View File

@ -591,19 +591,22 @@ std::unique_ptr<GrDrawOp> GrAtlasTextOp::CreateOpTestingOnly(GrRenderTargetConte
builder.drawTextUTF8(skPaint, font, text, textLen, drawOrigin);
auto glyphRunList = builder.useGlyphRunList();
if (glyphRunList.empty()) {
return nullptr;
}
const GrRecordingContextPriv& contextPriv = rtc->fContext->priv();
GrSDFTOptions SDFOptions = rtc->fContext->priv().SDFTOptions();
if (glyphRunList.empty()) {
return nullptr;
}
sk_sp<GrTextBlob> blob = GrTextBlob::Make(glyphRunList, drawMatrix);
SkGlyphRunListPainter* painter = &rtc->fGlyphPainter;
painter->processGlyphRunList(
glyphRunList, drawMatrix, rtc->surfaceProps(),
contextPriv.caps()->shaderCaps()->supportsDistanceFieldText(),
SDFOptions, blob.get());
if (!blob->firstSubRun()) {
return nullptr;
}
return GrAtlasTextOp::MakeBitmap(rtc,
skPaint,

View File

@ -212,6 +212,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrAtlasTextOpPreparation, reporter, ctxInfo)
std::unique_ptr<GrDrawOp> op =
GrAtlasTextOp::CreateOpTestingOnly(
rtc.get(), paint, font, matrixProvider, text, 16, 16);
if (!op) {
return;
}
bool hasMixedSampledCoverage = false;
op->finalize(*context->priv().caps(), nullptr, hasMixedSampledCoverage, GrClampType::kAuto);

View File

@ -200,6 +200,7 @@ void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext
uint32_t index = random->nextULessThan(static_cast<uint32_t>(kTotal));
auto op = gFactories[index](
std::move(paint), random, context, renderTargetContext->numSamples());
SkASSERT(op);
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
if (op) {
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
}
}