diff --git a/src/text/gpu/TextBlob.cpp b/src/text/gpu/TextBlob.cpp index 8cfaefa1f8..445593d323 100644 --- a/src/text/gpu/TextBlob.cpp +++ b/src/text/gpu/TextBlob.cpp @@ -2177,6 +2177,18 @@ SubRunContainerOwner SubRunContainer::MakeFromBufferInAlloc(SkReadBuffer& buffer return container; } +size_t SubRunContainer::EstimateAllocSize(const SkGlyphRunList& glyphRunList) { + // The difference in alignment from the per-glyph data to the SubRun; + constexpr size_t alignDiff = alignof(DirectMaskSubRun) - alignof(DevicePosition); + constexpr size_t vertexDataToSubRunPadding = alignDiff > 0 ? alignDiff : 0; + size_t totalGlyphCount = glyphRunList.totalGlyphCount(); + // This is optimized for DirectMaskSubRun which is by far the most common case. + return totalGlyphCount * sizeof(DevicePosition) + + GlyphVector::GlyphVectorSize(totalGlyphCount) + + glyphRunList.runCount() * (sizeof(DirectMaskSubRun) + vertexDataToSubRunPadding) + + sizeof(SubRunContainer); +} + std::tuple SubRunContainer::MakeInAlloc( const SkGlyphRunList& glyphRunList, const SkMatrix& positionMatrix, @@ -2560,18 +2572,7 @@ sk_sp SlugImpl::Make(const SkMatrixProvider& viewMatrix, const SkPaint& drawingPaint, SkStrikeDeviceInfo strikeDeviceInfo, SkStrikeForGPUCacheInterface* strikeCache) { - // The difference in alignment from the per-glyph data to the SubRun; - constexpr size_t alignDiff = alignof(DirectMaskSubRun) - alignof(DevicePosition); - constexpr size_t vertexDataToSubRunPadding = alignDiff > 0 ? alignDiff : 0; - size_t totalGlyphCount = glyphRunList.totalGlyphCount(); - // The bytesNeededForSubRun is optimized for DirectMaskSubRun which is by far the most - // common case. - size_t subRunSizeHint = - totalGlyphCount * sizeof(DevicePosition) - + GlyphVector::GlyphVectorSize(totalGlyphCount) - + glyphRunList.runCount() * (sizeof(DirectMaskSubRun) + vertexDataToSubRunPadding) - + sizeof(SubRunContainer); - + size_t subRunSizeHint = SubRunContainer::EstimateAllocSize(glyphRunList); auto [initializer, _, alloc] = SubRunAllocator::AllocateClassMemoryAndArena(subRunSizeHint); @@ -2720,18 +2721,7 @@ sk_sp TextBlob::Make(const SkGlyphRunList& glyphRunList, const SkMatrix& positionMatrix, SkStrikeDeviceInfo strikeDeviceInfo, SkStrikeForGPUCacheInterface* strikeCache) { - // The difference in alignment from the per-glyph data to the SubRun; - constexpr size_t alignDiff = alignof(DirectMaskSubRun) - alignof(DevicePosition); - constexpr size_t vertexDataToSubRunPadding = alignDiff > 0 ? alignDiff : 0; - size_t totalGlyphCount = glyphRunList.totalGlyphCount(); - - // The neededForSubRun is optimized for DirectMaskSubRun which is by far the most common case. - size_t subRunSizeHint = - totalGlyphCount * sizeof(DevicePosition) - + GlyphVector::GlyphVectorSize(totalGlyphCount) - + glyphRunList.runCount() * (sizeof(DirectMaskSubRun) + vertexDataToSubRunPadding) - + sizeof(SubRunContainer); - + size_t subRunSizeHint = SubRunContainer::EstimateAllocSize(glyphRunList); auto [initializer, totalMemoryAllocated, alloc] = SubRunAllocator::AllocateClassMemoryAndArena(subRunSizeHint); diff --git a/src/text/gpu/TextBlob.h b/src/text/gpu/TextBlob.h index 9fc44012eb..e150023f24 100644 --- a/src/text/gpu/TextBlob.h +++ b/src/text/gpu/TextBlob.h @@ -215,6 +215,8 @@ public: sktext::gpu::SubRunAllocator* alloc, const char* tag); + static size_t EstimateAllocSize(const SkGlyphRunList& glyphRunList); + #if SK_SUPPORT_GPU void draw(SkCanvas* canvas, const GrClip* clip,