Bug 1560582 - limit Skia glyph batch sizes. r=jrmuizel
authorLee Salzman <lsalzman@mozilla.com>
Thu, 27 Jun 2019 02:42:24 +0000
changeset 480280 e57ef2080d3fe256ed188285f178ab97729af28d
parent 480279 40986c1d78aa9a4cd6c9cf418f02428e5909690e
child 480281 2dc839c3e6b329cea80f281b50da96a3d5bbc6d0
push id36208
push userccoroiu@mozilla.com
push dateThu, 27 Jun 2019 09:34:48 +0000
treeherdermozilla-central@70e7c3ef6cae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1560582
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1560582 - limit Skia glyph batch sizes. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D36148
gfx/2d/DrawTargetSkia.cpp
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -1369,24 +1369,32 @@ void DrawTargetSkia::DrawGlyphs(ScaledFo
     }
 #endif
     default:
       break;
   }
 
   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<SkTextBlob> text = builder.make();
+    mCanvas->drawTextBlob(text, 0, 0, paint.mPaint);
   }
-  sk_sp<SkTextBlob> text = builder.make();
-  mCanvas->drawTextBlob(text, 0, 0, paint.mPaint);
 }
 
 void DrawTargetSkia::FillGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer,
                                 const Pattern& aPattern,
                                 const DrawOptions& aOptions) {
   DrawGlyphs(aFont, aBuffer, aPattern, nullptr, aOptions);
 }