diff options
author | Brian Salomon <bsalomon@google.com> | 2017-12-15 11:41:09 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-15 17:06:08 +0000 |
commit | 0215e39d7e415d0530231df6ad20d5f215c72152 (patch) | |
tree | 91fec56dae447ceb15e1743117a8ff272c60a7c3 /src/gpu/text/GrAtlasTextBlob.cpp | |
parent | 29c14a760682e2c449fa043b5e8b69937cb58f3a (diff) |
Transform vertices for distance field glyphs on CPU.
This allows batching of DF draws with different view matrices.
For perspective matrices this means the transformed position vertex
attribute must have w values. Currently, non-perspective DF draws still
use 2 component positions, though this could be changed in the future.
Consequently, perspective draws can batch with other perspective draws
but not non-perspective draws.
Adds a GM to test batching and reusing the same blobs with both perspective
and non-perspective matrices.
Change-Id: I0e42c5449ebf3a5a54025dbcdec824d904d5bd9e
Reviewed-on: https://skia-review.googlesource.com/79900
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src/gpu/text/GrAtlasTextBlob.cpp')
-rw-r--r-- | src/gpu/text/GrAtlasTextBlob.cpp | 79 |
1 files changed, 31 insertions, 48 deletions
diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp index 0b25a34ed1..02f3ab0a21 100644 --- a/src/gpu/text/GrAtlasTextBlob.cpp +++ b/src/gpu/text/GrAtlasTextBlob.cpp @@ -96,7 +96,13 @@ void GrAtlasTextBlob::appendGlyph(int runIndex, run.fInitialized = true; - size_t vertexStride = GetVertexStride(format); + bool hasW = subRun->hasWCoord(); + // DF glyphs drawn in perspective must always have a w coord. + SkASSERT(hasW || !subRun->drawAsDistanceFields() || !fInitialViewMatrix.hasPerspective()); + // Non-DF glyphs should never have a w coord. + SkASSERT(!hasW || subRun->drawAsDistanceFields()); + + size_t vertexStride = GetVertexStride(format, hasW); subRun->setMaskFormat(format); @@ -105,53 +111,29 @@ void GrAtlasTextBlob::appendGlyph(int runIndex, intptr_t vertex = reinterpret_cast<intptr_t>(this->fVertices + subRun->vertexEndIndex()); - if (kARGB_GrMaskFormat != glyph->fMaskFormat) { - // V0 - SkPoint* position = reinterpret_cast<SkPoint*>(vertex); - position->set(positions.fLeft, positions.fTop); - SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); - *colorPtr = color; - vertex += vertexStride; - - // V1 - position = reinterpret_cast<SkPoint*>(vertex); - position->set(positions.fLeft, positions.fBottom); - colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); - *colorPtr = color; - vertex += vertexStride; - - // V2 - position = reinterpret_cast<SkPoint*>(vertex); - position->set(positions.fRight, positions.fTop); - colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); - *colorPtr = color; - vertex += vertexStride; - - // V3 - position = reinterpret_cast<SkPoint*>(vertex); - position->set(positions.fRight, positions.fBottom); - colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); - *colorPtr = color; - } else { - // V0 - SkPoint* position = reinterpret_cast<SkPoint*>(vertex); - position->set(positions.fLeft, positions.fTop); - vertex += vertexStride; - - // V1 - position = reinterpret_cast<SkPoint*>(vertex); - position->set(positions.fLeft, positions.fBottom); - vertex += vertexStride; - - // V2 - position = reinterpret_cast<SkPoint*>(vertex); - position->set(positions.fRight, positions.fTop); - vertex += vertexStride; - - // V3 - position = reinterpret_cast<SkPoint*>(vertex); - position->set(positions.fRight, positions.fBottom); - } + // 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) = {positions.fLeft, positions.fTop, 1.f}; + *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; + vertex += vertexStride; + + // V1 + *reinterpret_cast<SkPoint3*>(vertex) = {positions.fLeft, positions.fBottom, 1.f}; + *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; + vertex += vertexStride; + + // V2 + *reinterpret_cast<SkPoint3*>(vertex) = {positions.fRight, positions.fTop, 1.f}; + *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; + vertex += vertexStride; + + // V3 + *reinterpret_cast<SkPoint3*>(vertex) = {positions.fRight, positions.fBottom, 1.f}; + *reinterpret_cast<GrColor*>(vertex + colorOffset) = color; + subRun->appendVertices(vertexStride); fGlyphs[subRun->glyphEndIndex()] = glyph; subRun->glyphAppended(); @@ -185,6 +167,7 @@ bool GrAtlasTextBlob::mustRegenerate(const GrTextUtils::Paint& paint, return true; } + /** This could be relaxed for blobs with only distance field glyphs. */ if (fInitialViewMatrix.hasPerspective() && !fInitialViewMatrix.cheapEqualTo(viewMatrix)) { return true; } |