Move adding a glyph to a subRun from Run to SubRun
Change-Id: I61e7c42f27480b6d5923073a5f7eb5a27726a4b2 Reviewed-on: https://skia-review.googlesource.com/c/170424 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
parent
5f50f5776d
commit
96a1709964
@ -134,47 +134,11 @@ void GrTextBlob::Run::appendGlyph(GrTextBlob* blob,
|
||||
}
|
||||
|
||||
fInitialized = true;
|
||||
|
||||
bool hasW = subRun->hasWCoord();
|
||||
// glyphs drawn in perspective must always have a w coord.
|
||||
SkASSERT(hasW || !blob->fInitialViewMatrix.hasPerspective());
|
||||
|
||||
size_t vertexStride = GetVertexStride(format, hasW);
|
||||
|
||||
subRun->setMaskFormat(format);
|
||||
|
||||
subRun->joinGlyphBounds(glyphRect);
|
||||
subRun->setColor(color);
|
||||
|
||||
intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->vertexEndIndex());
|
||||
|
||||
// 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);
|
||||
// V0
|
||||
*reinterpret_cast<SkPoint3*>(vertex) = {glyphRect.fLeft, glyphRect.fTop, 1.f};
|
||||
*reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
|
||||
vertex += vertexStride;
|
||||
|
||||
// V1
|
||||
*reinterpret_cast<SkPoint3*>(vertex) = {glyphRect.fLeft, glyphRect.fBottom, 1.f};
|
||||
*reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
|
||||
vertex += vertexStride;
|
||||
|
||||
// V2
|
||||
*reinterpret_cast<SkPoint3*>(vertex) = {glyphRect.fRight, glyphRect.fTop, 1.f};
|
||||
*reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
|
||||
vertex += vertexStride;
|
||||
|
||||
// V3
|
||||
*reinterpret_cast<SkPoint3*>(vertex) = {glyphRect.fRight, glyphRect.fBottom, 1.f};
|
||||
*reinterpret_cast<GrColor*>(vertex + colorOffset) = color;
|
||||
|
||||
subRun->appendVertices(vertexStride);
|
||||
blob->fGlyphs[subRun->glyphEndIndex()] = glyph;
|
||||
subRun->glyphAppended();
|
||||
subRun->setNeedsTransform(needsTransform);
|
||||
|
||||
subRun->appendGlyph(blob, glyph, glyphRect);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,6 +303,47 @@ private:
|
||||
, fFlags(that.fFlags) {
|
||||
}
|
||||
|
||||
void appendGlyph(GrTextBlob* blob, GrGlyph* glyph, SkRect dstRect) {
|
||||
|
||||
this->joinGlyphBounds(dstRect);
|
||||
|
||||
bool hasW = this->hasWCoord();
|
||||
// glyphs drawn in perspective must always have a w coord.
|
||||
SkASSERT(hasW || !blob->fInitialViewMatrix.hasPerspective());
|
||||
auto maskFormat = this->maskFormat();
|
||||
size_t vertexStride = GetVertexStride(maskFormat, hasW);
|
||||
|
||||
intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + fVertexEndIndex);
|
||||
|
||||
// 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);
|
||||
// V0
|
||||
*reinterpret_cast<SkPoint3*>(vertex) = {dstRect.fLeft, dstRect.fTop, 1.f};
|
||||
*reinterpret_cast<GrColor*>(vertex + colorOffset) = fColor;
|
||||
vertex += vertexStride;
|
||||
|
||||
// V1
|
||||
*reinterpret_cast<SkPoint3*>(vertex) = {dstRect.fLeft, dstRect.fBottom, 1.f};
|
||||
*reinterpret_cast<GrColor*>(vertex + colorOffset) = fColor;
|
||||
vertex += vertexStride;
|
||||
|
||||
// V2
|
||||
*reinterpret_cast<SkPoint3*>(vertex) = {dstRect.fRight, dstRect.fTop, 1.f};
|
||||
*reinterpret_cast<GrColor*>(vertex + colorOffset) = fColor;
|
||||
vertex += vertexStride;
|
||||
|
||||
// V3
|
||||
*reinterpret_cast<SkPoint3*>(vertex) = {dstRect.fRight, dstRect.fBottom, 1.f};
|
||||
*reinterpret_cast<GrColor*>(vertex + colorOffset) = fColor;
|
||||
|
||||
fVertexEndIndex += vertexStride * kVerticesPerGlyph;
|
||||
blob->fGlyphs[fGlyphEndIndex++] = glyph;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO when this object is more internal, drop the privacy
|
||||
void resetBulkUseToken() { fBulkUseToken.reset(); }
|
||||
GrDrawOpAtlas::BulkUseTokenUpdater* bulkUseToken() { return &fBulkUseToken; }
|
||||
@ -316,14 +357,10 @@ private:
|
||||
size_t byteCount() const { return fVertexEndIndex - fVertexStartIndex; }
|
||||
size_t vertexStartIndex() const { return fVertexStartIndex; }
|
||||
size_t vertexEndIndex() const { return fVertexEndIndex; }
|
||||
void appendVertices(size_t vertexStride) {
|
||||
fVertexEndIndex += vertexStride * kVerticesPerGlyph;
|
||||
}
|
||||
|
||||
uint32_t glyphCount() const { return fGlyphEndIndex - fGlyphStartIndex; }
|
||||
uint32_t glyphStartIndex() const { return fGlyphStartIndex; }
|
||||
uint32_t glyphEndIndex() const { return fGlyphEndIndex; }
|
||||
void glyphAppended() { fGlyphEndIndex++; }
|
||||
void setColor(GrColor color) { fColor = color; }
|
||||
GrColor color() const { return fColor; }
|
||||
void setMaskFormat(GrMaskFormat format) { fMaskFormat = format; }
|
||||
|
Loading…
Reference in New Issue
Block a user