A change to cleanup some organization around df text

BUG=skia:

Review URL: https://codereview.chromium.org/1519083002
This commit is contained in:
joshualitt 2015-12-11 11:05:43 -08:00 committed by Commit bot
parent cad54b5366
commit 5425a9a180
2 changed files with 61 additions and 86 deletions

View File

@ -291,41 +291,32 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob,
PerSubRunInfo& subRun = runIdx.fSubRunInfo.back(); PerSubRunInfo& subRun = runIdx.fSubRunInfo.back();
subRun.setUseLCDText(runPaint.isLCDRenderText()); subRun.setUseLCDText(runPaint.isLCDRenderText());
subRun.setDrawAsDistanceFields(); subRun.setDrawAsDistanceFields();
SkGlyphCache* cache = this->setupCache(&cacheBlob->fRuns[run], dfPaint, nullptr, true);
SkTDArray<char> fallbackTxt;
SkTDArray<SkScalar> fallbackPos;
SkPoint dfOffset;
int scalarsPerPosition = 2;
switch (it.positioning()) { switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning: { case SkTextBlob::kDefault_Positioning: {
this->internalDrawDFText(cacheBlob, run, dfPaint, color, viewMatrix, this->internalDrawDFText(cacheBlob, run, cache, dfPaint, color, viewMatrix,
(const char *)it.glyphs(), textLen, (const char *)it.glyphs(), textLen,
x + offset.x(), y + offset.y(), textRatio, x + offset.x(), y + offset.y(), textRatio, runPaint);
&fallbackTxt, &fallbackPos, &dfOffset, runPaint);
break; break;
} }
case SkTextBlob::kHorizontal_Positioning: { case SkTextBlob::kHorizontal_Positioning: {
scalarsPerPosition = 1; SkPoint dfOffset = SkPoint::Make(x, y + offset.y());
dfOffset = SkPoint::Make(x, y + offset.y()); this->internalDrawDFPosText(cacheBlob, run, cache, dfPaint, color, viewMatrix,
this->internalDrawDFPosText(cacheBlob, run, dfPaint, color, viewMatrix,
(const char*)it.glyphs(), textLen, it.pos(), (const char*)it.glyphs(), textLen, it.pos(),
scalarsPerPosition, dfOffset, textRatio, 1, dfOffset, textRatio,
&fallbackTxt, &fallbackPos); runPaint);
break; break;
} }
case SkTextBlob::kFull_Positioning: { case SkTextBlob::kFull_Positioning: {
dfOffset = SkPoint::Make(x, y); SkPoint dfOffset = SkPoint::Make(x, y);
this->internalDrawDFPosText(cacheBlob, run, dfPaint, color, viewMatrix, this->internalDrawDFPosText(cacheBlob, run, cache, dfPaint, color, viewMatrix,
(const char*)it.glyphs(), textLen, it.pos(), (const char*)it.glyphs(), textLen, it.pos(),
scalarsPerPosition, dfOffset, textRatio, 2, dfOffset, textRatio, runPaint);
&fallbackTxt, &fallbackPos);
break; break;
} }
} }
if (fallbackTxt.count()) { SkGlyphCache::AttachCache(cache);
this->fallbackDrawPosText(cacheBlob, run, clip, color, runPaint, viewMatrix,
fallbackTxt, fallbackPos, scalarsPerPosition, dfOffset);
}
} else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) { } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) {
cacheBlob->fRuns[run].fDrawAsPaths = true; cacheBlob->fRuns[run].fDrawAsPaths = true;
} else { } else {
@ -418,7 +409,6 @@ inline void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob,
inline void GrAtlasTextContext::fallbackDrawPosText(GrAtlasTextBlob* blob, inline void GrAtlasTextContext::fallbackDrawPosText(GrAtlasTextBlob* blob,
int runIndex, int runIndex,
const GrClip& clip,
GrColor color, GrColor color,
const SkPaint& skPaint, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -460,11 +450,10 @@ GrAtlasTextContext::setupDFBlob(int glyphCount, const SkPaint& origPaint,
} }
inline GrAtlasTextBlob* inline GrAtlasTextBlob*
GrAtlasTextContext::createDrawTextBlob(const GrClip& clip, GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint, const SkPaint& skPaint,
const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, const char text[], size_t byteLength,
SkScalar x, SkScalar y, const SkIRect& regionClipBounds) { SkScalar x, SkScalar y) {
int glyphCount = skPaint.countText(text, byteLength); int glyphCount = skPaint.countText(text, byteLength);
GrAtlasTextBlob* blob; GrAtlasTextBlob* blob;
@ -472,17 +461,11 @@ GrAtlasTextContext::createDrawTextBlob(const GrClip& clip,
SkPaint dfPaint; SkPaint dfPaint;
SkScalar textRatio; SkScalar textRatio;
blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &textRatio); blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &textRatio);
SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], dfPaint, nullptr, true);
SkTDArray<char> fallbackTxt; this->internalDrawDFText(blob, 0, cache, dfPaint, paint.getColor(), viewMatrix, text,
SkTDArray<SkScalar> fallbackPos; byteLength, x, y, textRatio, skPaint);
SkPoint offset; SkGlyphCache::AttachCache(cache);
this->internalDrawDFText(blob, 0, dfPaint, paint.getColor(), viewMatrix, text,
byteLength, x, y, textRatio, &fallbackTxt, &fallbackPos,
&offset, skPaint);
if (fallbackTxt.count()) {
this->fallbackDrawPosText(blob, 0, clip, paint.getColor(), skPaint, viewMatrix,
fallbackTxt, fallbackPos, 2, offset);
}
} else { } else {
blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASize); blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASize);
blob->fViewMatrix = viewMatrix; blob->fViewMatrix = viewMatrix;
@ -496,12 +479,11 @@ GrAtlasTextContext::createDrawTextBlob(const GrClip& clip,
} }
inline GrAtlasTextBlob* inline GrAtlasTextBlob*
GrAtlasTextContext::createDrawPosTextBlob(const GrClip& clip, GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& skPaint,
const GrPaint& paint, const SkPaint& skPaint,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkIRect& regionClipBounds) { const SkPoint& offset) {
int glyphCount = skPaint.countText(text, byteLength); int glyphCount = skPaint.countText(text, byteLength);
GrAtlasTextBlob* blob; GrAtlasTextBlob* blob;
@ -509,16 +491,12 @@ GrAtlasTextContext::createDrawPosTextBlob(const GrClip& clip,
SkPaint dfPaint; SkPaint dfPaint;
SkScalar textRatio; SkScalar textRatio;
blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &textRatio); blob = this->setupDFBlob(glyphCount, skPaint, viewMatrix, &dfPaint, &textRatio);
SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], dfPaint, nullptr, true);
SkTDArray<char> fallbackTxt; this->internalDrawDFPosText(blob, 0, cache, dfPaint, paint.getColor(), viewMatrix, text,
SkTDArray<SkScalar> fallbackPos; byteLength, pos, scalarsPerPosition, offset, textRatio,
this->internalDrawDFPosText(blob, 0, dfPaint, paint.getColor(), viewMatrix, text, skPaint);
byteLength, pos, scalarsPerPosition, offset, SkGlyphCache::AttachCache(cache);
textRatio, &fallbackTxt, &fallbackPos);
if (fallbackTxt.count()) {
this->fallbackDrawPosText(blob, 0, clip, paint.getColor(), skPaint, viewMatrix,
fallbackTxt, fallbackPos, scalarsPerPosition, offset);
}
} else { } else {
blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASize); blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASize);
blob->fViewMatrix = viewMatrix; blob->fViewMatrix = viewMatrix;
@ -538,8 +516,7 @@ void GrAtlasTextContext::onDrawText(GrDrawContext* dc,
const char text[], size_t byteLength, const char text[], size_t byteLength,
SkScalar x, SkScalar y, const SkIRect& regionClipBounds) { SkScalar x, SkScalar y, const SkIRect& regionClipBounds) {
SkAutoTUnref<GrAtlasTextBlob> blob( SkAutoTUnref<GrAtlasTextBlob> blob(
this->createDrawTextBlob(clip, paint, skPaint, viewMatrix, this->createDrawTextBlob(paint, skPaint, viewMatrix, text, byteLength, x, y));
text, byteLength, x, y, regionClipBounds));
blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPaint, paint, blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPaint, paint,
clip, regionClipBounds); clip, regionClipBounds);
} }
@ -552,24 +529,22 @@ void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc,
const SkScalar pos[], int scalarsPerPosition, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkIRect& regionClipBounds) { const SkPoint& offset, const SkIRect& regionClipBounds) {
SkAutoTUnref<GrAtlasTextBlob> blob( SkAutoTUnref<GrAtlasTextBlob> blob(
this->createDrawPosTextBlob(clip, paint, skPaint, viewMatrix, this->createDrawPosTextBlob(paint, skPaint, viewMatrix,
text, byteLength, text, byteLength,
pos, scalarsPerPosition, pos, scalarsPerPosition,
offset, regionClipBounds)); offset));
blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPaint, paint, clip, blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPaint, paint, clip,
regionClipBounds); regionClipBounds);
} }
void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex, void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex,
SkGlyphCache* cache,
const SkPaint& skPaint, GrColor color, const SkPaint& skPaint, GrColor color,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, const char text[], size_t byteLength,
SkScalar x, SkScalar y, SkScalar x, SkScalar y,
SkScalar textRatio, SkScalar textRatio,
SkTDArray<char>* fallbackTxt,
SkTDArray<SkScalar>* fallbackPos,
SkPoint* offset,
const SkPaint& origPaint) { const SkPaint& origPaint) {
SkASSERT(byteLength == 0 || text != nullptr); SkASSERT(byteLength == 0 || text != nullptr);
@ -628,22 +603,22 @@ void GrAtlasTextContext::internalDrawDFText(GrAtlasTextBlob* blob, int runIndex,
} }
x -= alignX; x -= alignX;
y -= alignY; y -= alignY;
*offset = SkPoint::Make(x, y); SkPoint offset = SkPoint::Make(x, y);
this->internalDrawDFPosText(blob, runIndex, skPaint, color, viewMatrix, text, byteLength, this->internalDrawDFPosText(blob, runIndex, cache, skPaint, color, viewMatrix, text, byteLength,
positions.begin(), 2, *offset, textRatio, fallbackTxt, positions.begin(), 2, offset, textRatio, origPaint);
fallbackPos);
} }
void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runIndex, void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runIndex,
const SkPaint& skPaint, GrColor color, SkGlyphCache* cache,
const SkPaint& skPaint,
GrColor color,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkPoint& offset,
SkScalar textRatio, SkScalar textRatio,
SkTDArray<char>* fallbackTxt, const SkPaint& origPaint) {
SkTDArray<SkScalar>* fallbackPos) {
SkASSERT(byteLength == 0 || text != nullptr); SkASSERT(byteLength == 0 || text != nullptr);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
@ -653,10 +628,12 @@ void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd
return; return;
} }
SkTDArray<char> fallbackTxt;
SkTDArray<SkScalar> fallbackPos;
fCurrStrike = nullptr; fCurrStrike = nullptr;
SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc();
SkGlyphCache* cache = this->setupCache(&blob->fRuns[runIndex], skPaint, nullptr, true);
GrFontScaler* fontScaler = GetGrFontScaler(cache); GrFontScaler* fontScaler = GetGrFontScaler(cache);
const char* stop = text + byteLength; const char* stop = text + byteLength;
@ -677,10 +654,10 @@ void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd
x, y, color, fontScaler, x, y, color, fontScaler,
textRatio, viewMatrix)) { textRatio, viewMatrix)) {
// couldn't append, send to fallback // couldn't append, send to fallback
fallbackTxt->append(SkToInt(text-lastText), lastText); fallbackTxt.append(SkToInt(text-lastText), lastText);
*fallbackPos->append() = pos[0]; *fallbackPos.append() = pos[0];
if (2 == scalarsPerPosition) { if (2 == scalarsPerPosition) {
*fallbackPos->append() = pos[1]; *fallbackPos.append() = pos[1];
} }
} }
} }
@ -709,10 +686,10 @@ void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd
textRatio, textRatio,
viewMatrix)) { viewMatrix)) {
// couldn't append, send to fallback // couldn't append, send to fallback
fallbackTxt->append(SkToInt(text-lastText), lastText); fallbackTxt.append(SkToInt(text-lastText), lastText);
*fallbackPos->append() = pos[0]; *fallbackPos.append() = pos[0];
if (2 == scalarsPerPosition) { if (2 == scalarsPerPosition) {
*fallbackPos->append() = pos[1]; *fallbackPos.append() = pos[1];
} }
} }
} }
@ -720,7 +697,10 @@ void GrAtlasTextContext::internalDrawDFPosText(GrAtlasTextBlob* blob, int runInd
} }
} }
SkGlyphCache::AttachCache(cache); if (fallbackTxt.count()) {
this->fallbackDrawPosText(blob, runIndex, origPaint.getColor(), origPaint, viewMatrix,
fallbackTxt, fallbackPos, scalarsPerPosition, offset);
}
} }
bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex, bool GrAtlasTextContext::dfAppendGlyph(GrAtlasTextBlob* blob, int runIndex,
@ -803,13 +783,12 @@ DRAW_BATCH_TEST_DEFINE(TextBlobBatch) {
// Setup clip // Setup clip
GrClip clip; GrClip clip;
SkIRect noClip = SkIRect::MakeLargest();
// right now we don't handle textblobs, nor do we handle drawPosText. Since we only // right now we don't handle textblobs, nor do we handle drawPosText. Since we only
// intend to test the batch with this unit test, that is okay. // intend to test the batch with this unit test, that is okay.
SkAutoTUnref<GrAtlasTextBlob> blob( SkAutoTUnref<GrAtlasTextBlob> blob(
gTextContext->createDrawTextBlob(clip, grPaint, skPaint, viewMatrix, text, gTextContext->createDrawTextBlob(grPaint, skPaint, viewMatrix, text,
static_cast<size_t>(textLen), 0, 0, noClip)); static_cast<size_t>(textLen), 0, 0));
SkScalar transX = static_cast<SkScalar>(random->nextU()); SkScalar transX = static_cast<SkScalar>(random->nextU());
SkScalar transY = static_cast<SkScalar>(random->nextU()); SkScalar transY = static_cast<SkScalar>(random->nextU());

View File

@ -66,29 +66,27 @@ private:
// A helper for drawing BitmapText in a run of distance fields // A helper for drawing BitmapText in a run of distance fields
inline void fallbackDrawPosText(GrAtlasTextBlob*, int runIndex, inline void fallbackDrawPosText(GrAtlasTextBlob*, int runIndex,
const GrClip&, GrColor color, GrColor color,
const SkPaint&, const SkMatrix& viewMatrix, const SkPaint&, const SkMatrix& viewMatrix,
const SkTDArray<char>& fallbackTxt, const SkTDArray<char>& fallbackTxt,
const SkTDArray<SkScalar>& fallbackPos, const SkTDArray<SkScalar>& fallbackPos,
int scalarsPerPosition, int scalarsPerPosition,
const SkPoint& offset); const SkPoint& offset);
void internalDrawDFText(GrAtlasTextBlob*, int runIndex, const SkPaint&, void internalDrawDFText(GrAtlasTextBlob*, int runIndex,
SkGlyphCache*, const SkPaint&,
GrColor color, const SkMatrix& viewMatrix, GrColor color, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, const char text[], size_t byteLength,
SkScalar x, SkScalar y, SkScalar x, SkScalar y,
SkScalar textRatio, SkScalar textRatio, const SkPaint& origPaint);
SkTDArray<char>* fallbackTxt, void internalDrawDFPosText(GrAtlasTextBlob*, int runIndex,
SkTDArray<SkScalar>* fallbackPos, SkGlyphCache*, const SkPaint&,
SkPoint* offset, const SkPaint& origPaint);
void internalDrawDFPosText(GrAtlasTextBlob*, int runIndex, const SkPaint&,
GrColor color, const SkMatrix& viewMatrix, GrColor color, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkPoint& offset,
SkScalar textRatio, SkScalar textRatio,
SkTDArray<char>* fallbackTxt, const SkPaint& origPaint);
SkTDArray<SkScalar>* fallbackPos);
// sets up the descriptor on the blob and returns a detached cache. Client must attach // sets up the descriptor on the blob and returns a detached cache. Client must attach
inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd);
@ -104,17 +102,15 @@ private:
// Test methods // Test methods
// TODO this is really ugly. It'd be much nicer if positioning could be moved to batch // TODO this is really ugly. It'd be much nicer if positioning could be moved to batch
inline GrAtlasTextBlob* createDrawTextBlob(const GrClip&, const GrPaint&, inline GrAtlasTextBlob* createDrawTextBlob(const GrPaint&,
const SkPaint&, const SkMatrix& viewMatrix, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, const char text[], size_t byteLength,
SkScalar x, SkScalar y, SkScalar x, SkScalar y);
const SkIRect& regionClipBounds); inline GrAtlasTextBlob* createDrawPosTextBlob(const GrPaint&,
inline GrAtlasTextBlob* createDrawPosTextBlob(const GrClip&, const GrPaint&,
const SkPaint&, const SkMatrix& viewMatrix, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength, const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkPoint& offset);
const SkIRect& regionClipBounds);
const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable; } const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable; }
GrBatchTextStrike* fCurrStrike; GrBatchTextStrike* fCurrStrike;