From 7dab69c7dec74ccc42bdce0d59ca045dd10232eb Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Thu, 27 Jun 2019 02:42:24 +0000 Subject: [PATCH] Bug 1560582 - limit Skia glyph batch sizes. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D36148 --HG-- extra : moz-landing-system : lando --- gfx/2d/DrawTargetSkia.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/gfx/2d/DrawTargetSkia.cpp b/gfx/2d/DrawTargetSkia.cpp index b1a02fbcabac..aa634b366411 100644 --- a/gfx/2d/DrawTargetSkia.cpp +++ b/gfx/2d/DrawTargetSkia.cpp @@ -1374,14 +1374,22 @@ void DrawTargetSkia::DrawGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer, font.setSubpixel(useSubpixelText); - SkTextBlobBuilder builder; - auto runBuffer = builder.allocRunPos(font, aBuffer.mNumGlyphs); - for (uint32_t i = 0; i < aBuffer.mNumGlyphs; i++) { - runBuffer.glyphs[i] = aBuffer.mGlyphs[i].mIndex; - runBuffer.points()[i] = PointToSkPoint(aBuffer.mGlyphs[i].mPosition); + // Limit the amount of internal batch allocations Skia does. + const uint32_t kMaxGlyphBatchSize = 8192; + + for (uint32_t offset = 0; offset < aBuffer.mNumGlyphs;) { + uint32_t batchSize = + std::min(aBuffer.mNumGlyphs - offset, kMaxGlyphBatchSize); + SkTextBlobBuilder builder; + auto runBuffer = builder.allocRunPos(font, batchSize); + for (uint32_t i = 0; i < batchSize; i++, offset++) { + runBuffer.glyphs[i] = aBuffer.mGlyphs[offset].mIndex; + runBuffer.points()[i] = PointToSkPoint(aBuffer.mGlyphs[offset].mPosition); + } + + sk_sp text = builder.make(); + mCanvas->drawTextBlob(text, 0, 0, paint.mPaint); } - sk_sp text = builder.make(); - mCanvas->drawTextBlob(text, 0, 0, paint.mPaint); } void DrawTargetSkia::FillGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer,