Bug 1385159 - Use array on the stack to prevent buffer allocation in DrawTargetSkia::DrawGlyphs.
Originally, I want to use AutoArray to replace std::vector in
DrawTargetSkia::DrawGlyphs. But then I realize that we can not use nsTArray.h in
moz2D. So I decide to use a c array instead.
MozReview-Commit-ID: 2YzN3DUXzTi
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -1438,28 +1438,39 @@ DrawTargetSkia::DrawGlyphs(ScaledFont* a
}
#endif
default:
break;
}
paint.mPaint.setSubpixelText(useSubpixelText);
- std::vector<uint16_t> indices;
- std::vector<SkPoint> offsets;
- indices.resize(aBuffer.mNumGlyphs);
- offsets.resize(aBuffer.mNumGlyphs);
+ const uint32_t heapSize = 64;
+ uint16_t indicesOnStack[heapSize];
+ SkPoint offsetsOnStack[heapSize];
+ std::vector<uint16_t> indicesOnHeap;
+ std::vector<SkPoint> offsetsOnHeap;
+ uint16_t* indices = indicesOnStack;
+ SkPoint* offsets = offsetsOnStack;
+ if (aBuffer.mNumGlyphs > heapSize) {
+ // Heap allocation/ deallocation is slow, use it only if we need a
+ // bigger(>heapSize) buffer.
+ indicesOnHeap.resize(aBuffer.mNumGlyphs);
+ offsetsOnHeap.resize(aBuffer.mNumGlyphs);
+ indices = (uint16_t*)&indicesOnHeap.front();
+ offsets = (SkPoint*)&offsetsOnHeap.front();
+ }
for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
indices[i] = aBuffer.mGlyphs[i].mIndex;
offsets[i].fX = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.x);
offsets[i].fY = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.y);
}
- mCanvas->drawPosText(&indices.front(), aBuffer.mNumGlyphs*2, &offsets.front(), paint.mPaint);
+ mCanvas->drawPosText(indices, aBuffer.mNumGlyphs*2, offsets, paint.mPaint);
}
void
DrawTargetSkia::FillGlyphs(ScaledFont* aFont,
const GlyphBuffer& aBuffer,
const Pattern& aPattern,
const DrawOptions& aOptions,
const GlyphRenderingOptions* aRenderingOptions)