Bug 1560582 - Limit Skia glyph batch sizes. r=jrmuizel, a=RyanVM
authorLee Salzman <lsalzman@mozilla.com>
Thu, 27 Jun 2019 02:42:24 +0000
changeset 534096 48a056813b7d4ccec53ec8ebcc0c6c93fcb06f06
parent 534095 e106f30c1f95336718ecefb4e565f97f5f11c274
child 534097 6d5726d8218286096bd1b47a2edb99d57ed4ce16
push id11517
push userryanvm@gmail.com
push dateFri, 28 Jun 2019 21:36:12 +0000
treeherdermozilla-beta@6d5726d82182 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, RyanVM
bugs1560582
milestone68.0
Bug 1560582 - Limit Skia glyph batch sizes. r=jrmuizel, a=RyanVM 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);
 }