diff --git a/src/gpu/GrAtlasTextBlob.cpp b/src/gpu/GrAtlasTextBlob.cpp index 3fb7ac99c1..21f2975805 100644 --- a/src/gpu/GrAtlasTextBlob.cpp +++ b/src/gpu/GrAtlasTextBlob.cpp @@ -7,6 +7,69 @@ #include "GrAtlasTextBlob.h" +void GrAtlasTextBlob::appendGlyph(Run* run, + Run::SubRunInfo* subRun, + const SkRect& positions, GrColor color, + size_t vertexStride, bool useVertexColor, + GrGlyph* glyph) { + run->fVertexBounds.joinNonEmptyArg(positions); + run->fColor = color; + + intptr_t vertex = reinterpret_cast(this->fVertices + subRun->vertexEndIndex()); + + if (useVertexColor) { + // V0 + SkPoint* position = reinterpret_cast(vertex); + position->set(positions.fLeft, positions.fTop); + SkColor* colorPtr = reinterpret_cast(vertex + sizeof(SkPoint)); + *colorPtr = color; + vertex += vertexStride; + + // V1 + position = reinterpret_cast(vertex); + position->set(positions.fLeft, positions.fBottom); + colorPtr = reinterpret_cast(vertex + sizeof(SkPoint)); + *colorPtr = color; + vertex += vertexStride; + + // V2 + position = reinterpret_cast(vertex); + position->set(positions.fRight, positions.fBottom); + colorPtr = reinterpret_cast(vertex + sizeof(SkPoint)); + *colorPtr = color; + vertex += vertexStride; + + // V3 + position = reinterpret_cast(vertex); + position->set(positions.fRight, positions.fTop); + colorPtr = reinterpret_cast(vertex + sizeof(SkPoint)); + *colorPtr = color; + } else { + // V0 + SkPoint* position = reinterpret_cast(vertex); + position->set(positions.fLeft, positions.fTop); + vertex += vertexStride; + + // V1 + position = reinterpret_cast(vertex); + position->set(positions.fLeft, positions.fBottom); + vertex += vertexStride; + + // V2 + position = reinterpret_cast(vertex); + position->set(positions.fRight, positions.fBottom); + vertex += vertexStride; + + // V3 + position = reinterpret_cast(vertex); + position->set(positions.fRight, positions.fTop); + } + subRun->appendVertices(vertexStride); + fGlyphs[subRun->glyphEndIndex()] = glyph; + subRun->glyphAppended(); +} + +// TODO get this code building again #ifdef CACHE_SANITY_CHECK void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) { SkASSERT(l.fSize == r.fSize); diff --git a/src/gpu/GrAtlasTextBlob.h b/src/gpu/GrAtlasTextBlob.h index 09f9dc01a8..22e2298a4e 100644 --- a/src/gpu/GrAtlasTextBlob.h +++ b/src/gpu/GrAtlasTextBlob.h @@ -93,6 +93,7 @@ struct GrAtlasTextBlob : public SkRefCnt { , fUseLCDText(that.fUseLCDText) { } + // TODO when this object is more internal, drop the privacy void resetBulkUseToken() { fBulkUseToken.reset(); } GrBatchAtlas::BulkUseTokenUpdater* bulkUseToken() { return &fBulkUseToken; } void setStrike(GrBatchTextStrike* strike) { fStrike.reset(SkRef(strike)); } @@ -102,23 +103,27 @@ struct GrAtlasTextBlob : public SkRefCnt { uint64_t atlasGeneration() const { return fAtlasGeneration; } size_t byteCount() const { return fVertexEndIndex - fVertexStartIndex; } - void setVertexStartIndex(size_t vertStartIndex) { fVertexStartIndex = vertStartIndex;} size_t vertexStartIndex() const { return fVertexStartIndex; } - void setVertexEndIndex(size_t vertEndIndex) { fVertexEndIndex = vertEndIndex; } size_t vertexEndIndex() const { return fVertexEndIndex; } void appendVertices(size_t vertexStride) { fVertexEndIndex += vertexStride * kVerticesPerGlyph; } uint32_t glyphCount() const { return fGlyphEndIndex - fGlyphStartIndex; } - void setGlyphStartIndex(uint32_t glyphStartIndex) { fGlyphStartIndex = glyphStartIndex;} uint32_t glyphStartIndex() const { return fGlyphStartIndex; } - void setGlyphEndIndex(uint32_t glyphEndIndex) { fGlyphEndIndex = glyphEndIndex; } uint32_t glyphEndIndex() const { return fGlyphEndIndex; } void glyphAppended() { fGlyphEndIndex++; } void setMaskFormat(GrMaskFormat format) { fMaskFormat = format; } GrMaskFormat maskFormat() const { return fMaskFormat; } + void setAsSuccessor(const SubRunInfo& prev) { + fGlyphStartIndex = prev.glyphEndIndex(); + fGlyphEndIndex = prev.glyphEndIndex(); + + fVertexStartIndex = prev.vertexEndIndex(); + fVertexEndIndex = prev.vertexEndIndex(); + } + // df properties void setUseLCDText(bool useLCDText) { fUseLCDText = useLCDText; } bool hasUseLCDText() const { return fUseLCDText; } @@ -141,13 +146,9 @@ struct GrAtlasTextBlob : public SkRefCnt { SubRunInfo& push_back() { // Forward glyph / vertex information to seed the new sub run SubRunInfo& newSubRun = fSubRunInfo.push_back(); - SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1); + const SubRunInfo& prevSubRun = fSubRunInfo.fromBack(1); - newSubRun.setGlyphStartIndex(prevSubRun.glyphEndIndex()); - newSubRun.setGlyphEndIndex(prevSubRun.glyphEndIndex()); - - newSubRun.setVertexStartIndex(prevSubRun.vertexEndIndex()); - newSubRun.setVertexEndIndex(prevSubRun.vertexEndIndex()); + newSubRun.setAsSuccessor(prevSubRun); return newSubRun; } static const int kMinSubRuns = 1; @@ -269,11 +270,22 @@ struct GrAtlasTextBlob : public SkRefCnt { bool hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType); } void setHasDistanceField() { fTextType |= kHasDistanceField_TextType; } void setHasBitmap() { fTextType |= kHasBitmap_TextType; } - void appendGlyph(Run::SubRunInfo* subrun, GrGlyph* glyph) { - this->fGlyphs[subrun->glyphEndIndex()] = glyph; - subrun->glyphAppended(); + + void push_back_run(int currRun) { + SkASSERT(currRun < fRunCount); + if (currRun > 0) { + Run::SubRunInfo& newRun = fRuns[currRun].fSubRunInfo.back(); + Run::SubRunInfo& lastRun = fRuns[currRun - 1].fSubRunInfo.back(); + newRun.setAsSuccessor(lastRun); + } } + void appendGlyph(Run* run, + Run::SubRunInfo* subRun, + const SkRect& positions, GrColor color, + size_t vertexStride, bool useVertexColor, + GrGlyph* glyph); + static const int kVerticesPerGlyph = 4; #ifdef CACHE_SANITY_CHECK diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp index cac52fb2f0..5023857426 100644 --- a/src/gpu/GrAtlasTextContext.cpp +++ b/src/gpu/GrAtlasTextContext.cpp @@ -461,17 +461,7 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, runPaint.setFlags(FilterTextFlags(fSurfaceProps, runPaint)); - // setup vertex / glyphIndex for the new run - if (run > 0) { - PerSubRunInfo& newRun = cacheBlob->fRuns[run].fSubRunInfo.back(); - PerSubRunInfo& lastRun = cacheBlob->fRuns[run - 1].fSubRunInfo.back(); - - newRun.setVertexStartIndex(lastRun.vertexEndIndex()); - newRun.setVertexEndIndex(lastRun.vertexEndIndex()); - - newRun.setGlyphStartIndex(lastRun.glyphEndIndex()); - newRun.setGlyphEndIndex(lastRun.glyphEndIndex()); - } + cacheBlob->push_back_run(run); if (this->canDrawAsDistanceFields(runPaint, viewMatrix)) { cacheBlob->setHasDistanceField(); @@ -1011,7 +1001,7 @@ void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, subRun = &run.push_back(); subRun->setStrike(fCurrStrike); } else if (!run.fInitialized) { - subRun->setStrike(SkRef(fCurrStrike)); + subRun->setStrike(fCurrStrike); } run.fInitialized = true; @@ -1024,8 +1014,7 @@ void GrAtlasTextContext::bmpAppendGlyph(GrAtlasTextBlob* blob, int runIndex, r.fRight = r.fLeft + SkIntToScalar(width); r.fBottom = r.fTop + SkIntToScalar(height); subRun->setMaskFormat(format); - this->appendGlyphCommon(blob, &run, subRun, r, color, vertexStride, kA8_GrMaskFormat == format, - glyph); + blob->appendGlyph(&run, subRun, r, color, vertexStride, kA8_GrMaskFormat == format, glyph); } bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, @@ -1085,8 +1074,7 @@ bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, subRun->hasUseLCDText()); bool useColorVerts = !subRun->hasUseLCDText(); - this->appendGlyphCommon(blob, &run, subRun, glyphRect, color, vertexStride, useColorVerts, - glyph); + blob->appendGlyph(&run, subRun, glyphRect, color, vertexStride, useColorVerts, glyph); return true; } @@ -1105,67 +1093,6 @@ inline void GrAtlasTextContext::appendGlyphPath(GrAtlasTextBlob* blob, GrGlyph* blob->fBigGlyphs.push_back(GrAtlasTextBlob::BigGlyph(*glyph->fPath, x, y, scale, applyVM)); } -inline void GrAtlasTextContext::appendGlyphCommon(GrAtlasTextBlob* blob, Run* run, - Run::SubRunInfo* subRun, - const SkRect& positions, GrColor color, - size_t vertexStride, bool useVertexColor, - GrGlyph* glyph) { - blob->appendGlyph(subRun, glyph); - run->fVertexBounds.joinNonEmptyArg(positions); - run->fColor = color; - - intptr_t vertex = reinterpret_cast(blob->fVertices + subRun->vertexEndIndex()); - - if (useVertexColor) { - // V0 - SkPoint* position = reinterpret_cast(vertex); - position->set(positions.fLeft, positions.fTop); - SkColor* colorPtr = reinterpret_cast(vertex + sizeof(SkPoint)); - *colorPtr = color; - vertex += vertexStride; - - // V1 - position = reinterpret_cast(vertex); - position->set(positions.fLeft, positions.fBottom); - colorPtr = reinterpret_cast(vertex + sizeof(SkPoint)); - *colorPtr = color; - vertex += vertexStride; - - // V2 - position = reinterpret_cast(vertex); - position->set(positions.fRight, positions.fBottom); - colorPtr = reinterpret_cast(vertex + sizeof(SkPoint)); - *colorPtr = color; - vertex += vertexStride; - - // V3 - position = reinterpret_cast(vertex); - position->set(positions.fRight, positions.fTop); - colorPtr = reinterpret_cast(vertex + sizeof(SkPoint)); - *colorPtr = color; - } else { - // V0 - SkPoint* position = reinterpret_cast(vertex); - position->set(positions.fLeft, positions.fTop); - vertex += vertexStride; - - // V1 - position = reinterpret_cast(vertex); - position->set(positions.fLeft, positions.fBottom); - vertex += vertexStride; - - // V2 - position = reinterpret_cast(vertex); - position->set(positions.fRight, positions.fBottom); - vertex += vertexStride; - - // V3 - position = reinterpret_cast(vertex); - position->set(positions.fRight, positions.fTop); - } - subRun->appendVertices(vertexStride); -} - void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, const SkTextBlobRunIterator& it, const GrClip& clip, const SkPaint& skPaint, diff --git a/src/gpu/GrAtlasTextContext.h b/src/gpu/GrAtlasTextContext.h index 70eabd21f8..04f3968a91 100644 --- a/src/gpu/GrAtlasTextContext.h +++ b/src/gpu/GrAtlasTextContext.h @@ -65,10 +65,6 @@ private: inline void appendGlyphPath(GrAtlasTextBlob*, GrGlyph*, GrFontScaler*, const SkGlyph&, SkScalar x, SkScalar y, SkScalar scale = 1.0f, bool applyVM = false); - inline void appendGlyphCommon(GrAtlasTextBlob*, Run*, Run::SubRunInfo*, - const SkRect& positions, GrColor color, - size_t vertexStride, bool useVertexColor, - GrGlyph*); inline void flushRunAsPaths(GrDrawContext*, const SkTextBlobRunIterator&, const GrClip& clip,