Specialize vertex size for GrTextBlob

The old code assumes a conservative size for vertices of 20 bytes,
but this only happens in perspective or strange DFT modes. This can
be reduced to 16 bytes in the non-perspective case a savings of 20%

Change-Id: Ife7e7cc4bd00798f173c5390c3100605908e6276
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/257923
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Herb Derby 2019-12-04 14:15:41 -05:00 committed by Skia Commit-Bot
parent 7a671982cd
commit e74c77685d

View File

@ -29,9 +29,20 @@ sk_sp<GrTextBlob> GrTextBlob::Make(int glyphCount,
SkPoint origin,
GrColor color,
bool forceWForDistanceFields) {
// Default to no perspective. Implies one of the following vertex formats: kColorTextVASize,
// kGrayTextVASize, kLCDTextVASize.
static_assert(kColorTextVASize <= kGrayTextVASize && kLCDTextVASize <= kGrayTextVASize);
size_t quadSize = kVerticesPerGlyph * kGrayTextVASize;
if (viewMatrix.hasPerspective() || forceWForDistanceFields) {
// Perspective. Implies one of the following vertex formats: kColorTextPerspectiveVASize,
// kGrayTextDFPerspectiveVASize.
static_assert(kColorTextPerspectiveVASize <= kGrayTextDFPerspectiveVASize);
quadSize = kVerticesPerGlyph * kGrayTextDFPerspectiveVASize;
}
// We allocate size for the GrTextBlob itself, plus size for the vertices array,
// and size for the glyphIds array.
size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
size_t verticesCount = glyphCount * quadSize;
size_t blobStart = 0;
size_t vertex = sk_align<alignof(char)> (blobStart + sizeof(GrTextBlob) * 1);