Internalize color offset calculation to SubRun

Change-Id: I76f57a11c66c708462e4c91cc5cf8967d60b78c5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/261442
Commit-Queue: Herb Derby <herb@google.com>
Auto-Submit: Herb Derby <herb@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Herb Derby 2019-12-23 15:26:44 -05:00 committed by Skia Commit-Bot
parent a2d7225c0f
commit 3d3150c89c

View File

@ -18,6 +18,7 @@
#include "src/gpu/text/GrTextBlob.h"
#include "src/gpu/text/GrTextTarget.h"
#include <cstddef>
#include <new>
static SkVector calculate_translation(bool applyVM,
@ -94,6 +95,7 @@ public:
GrMaskFormat maskFormat() const;
size_t vertexStride() const;
size_t colorOffset() const;
const SkRect& vertexBounds() const;
void joinGlyphBounds(const SkRect& glyphBounds);
@ -171,15 +173,12 @@ void GrTextBlob::SubRun::appendGlyphs(const SkZip<SkGlyphVariant, SkPoint>& draw
SkScalar strikeToSource = fStrikeSpec.strikeToSourceRatio();
GrGlyph** glyphCursor = fGlyphs.data();
char* vertexCursor = fVertexData.data();
bool hasW = this->hasW();
GrColor color = this->color();
// glyphs drawn in perspective must always have a w coord.
SkASSERT(hasW || !fBlob->fInitialMatrix.hasPerspective());
size_t vertexStride = this->vertexStride();
// We always write the third position component used by SDFs. If it is unused it gets
// overwritten. Similarly, we always write the color and the blob will later overwrite it
// with texture coords if it is unused.
size_t colorOffset = hasW ? sizeof(SkPoint3) : sizeof(SkPoint);
size_t colorOffset = this->colorOffset();
for (auto [variant, pos] : drawables) {
SkGlyph* skGlyph = variant;
GrGlyph* grGlyph = grStrike->getGlyph(*skGlyph);
@ -231,6 +230,9 @@ GrMaskFormat GrTextBlob::SubRun::maskFormat() const { return fMaskFormat; }
size_t GrTextBlob::SubRun::vertexStride() const {
return GetVertexStride(this->maskFormat(), this->hasW());
}
size_t GrTextBlob::SubRun::colorOffset() const {
return this->hasW() ? offsetof(SDFT3DVertex, color) : offsetof(Mask2DVertex, color);
}
const SkRect& GrTextBlob::SubRun::vertexBounds() const { return fVertexBounds; }
void GrTextBlob::SubRun::joinGlyphBounds(const SkRect& glyphBounds) {
@ -612,6 +614,9 @@ GrTextBlob::SubRun* GrTextBlob::makeSubRun(SubRunType type,
GrMaskFormat format) {
SkSpan<GrGlyph*> glyphs{fAlloc.makeArrayDefault<GrGlyph*>(drawables.size()), drawables.size()};
bool hasW = this->hasW(type);
SkASSERT(!fInitialMatrix.hasPerspective() || hasW);
size_t vertexDataSize = drawables.size() * GetVertexStride(format, hasW) * kVerticesPerGlyph;
SkSpan<char> vertexData{fAlloc.makeArrayDefault<char>(vertexDataSize), vertexDataSize};