start to chip away at friending of GrAtlasTextBatch/GrAtlasTextBlob

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1684253002

Review URL: https://codereview.chromium.org/1684253002
This commit is contained in:
joshualitt 2016-02-11 12:42:02 -08:00 committed by Commit bot
parent 0eed945294
commit bc81111f24
3 changed files with 44 additions and 39 deletions

View File

@ -147,7 +147,6 @@ inline void GrAtlasTextBatch::regenBlob(Target* target, FlushInfo* flushInfo, Bl
*desc = newDesc; *desc = newDesc;
*cache = SkGlyphCache::DetachCache(run->fTypeface, *desc); *cache = SkGlyphCache::DetachCache(run->fTypeface, *desc);
*scaler = GrTextContext::GetGrFontScaler(*cache); *scaler = GrTextContext::GetGrFontScaler(*cache);
strike = info->strike();
*typeface = run->fTypeface; *typeface = run->fTypeface;
} }

View File

@ -81,39 +81,9 @@ public:
void init() { void init() {
const Geometry& geo = fGeoData[0]; const Geometry& geo = fGeoData[0];
fBatch.fColor = geo.fColor; fBatch.fColor = geo.fColor;
fBatch.fViewMatrix = geo.fBlob->fViewMatrix; fBatch.fViewMatrix = geo.fBlob->viewMatrix();
// We don't yet position distance field text on the cpu, so we have to map the vertex bounds geo.fBlob->computeSubRunBounds(&fBounds, geo.fRun, geo.fSubRun);
// into device space.
// We handle vertex bounds differently for distance field text and bitmap text because
// the vertex bounds of bitmap text are in device space. If we are flushing multiple runs
// from one blob then we are going to pay the price here of mapping the rect for each run.
const Run& run = geo.fBlob->fRuns[geo.fRun];
SkRect bounds = run.fSubRunInfo[geo.fSubRun].vertexBounds();
if (run.fSubRunInfo[geo.fSubRun].drawAsDistanceFields()) {
// Distance field text is positioned with the (X,Y) as part of the glyph position,
// and currently the view matrix is applied on the GPU
bounds.offset(geo.fBlob->fX - geo.fBlob->fInitialX,
geo.fBlob->fY - geo.fBlob->fInitialY);
fBatch.fViewMatrix.mapRect(&bounds);
this->setBounds(bounds);
} else {
// Bitmap text is fully positioned on the CPU, and offset by an (X,Y) translate in
// device space.
SkMatrix boundsMatrix = geo.fBlob->fInitialViewMatrixInverse;
boundsMatrix.postTranslate(-geo.fBlob->fInitialX, -geo.fBlob->fInitialY);
boundsMatrix.postTranslate(geo.fBlob->fX, geo.fBlob->fY);
boundsMatrix.postConcat(geo.fBlob->fViewMatrix);
boundsMatrix.mapRect(&bounds);
// Due to floating point numerical inaccuracies, we have to round out here
SkRect roundedOutBounds;
bounds.roundOut(&roundedOutBounds);
this->setBounds(roundedOutBounds);
}
} }
const char* name() const override { return "TextBatch"; } const char* name() const override { return "TextBatch"; }

View File

@ -200,6 +200,40 @@ public:
const GrClip& clip, const GrClip& clip,
const SkIRect& clipBounds); const SkIRect& clipBounds);
void computeSubRunBounds(SkRect* outBounds, int runIndex, int subRunIndex) {
// We don't yet position distance field text on the cpu, so we have to map the vertex bounds
// into device space.
// We handle vertex bounds differently for distance field text and bitmap text because
// the vertex bounds of bitmap text are in device space. If we are flushing multiple runs
// from one blob then we are going to pay the price here of mapping the rect for each run.
const Run& run = fRuns[runIndex];
const Run::SubRunInfo& subRun = run.fSubRunInfo[subRunIndex];
*outBounds = subRun.vertexBounds();
if (subRun.drawAsDistanceFields()) {
// Distance field text is positioned with the (X,Y) as part of the glyph position,
// and currently the view matrix is applied on the GPU
outBounds->offset(fX - fInitialX, fY - fInitialY);
fViewMatrix.mapRect(outBounds);
} else {
// Bitmap text is fully positioned on the CPU, and offset by an (X,Y) translate in
// device space.
SkMatrix boundsMatrix = fInitialViewMatrixInverse;
boundsMatrix.postTranslate(-fInitialX, -fInitialY);
boundsMatrix.postTranslate(fX, fY);
boundsMatrix.postConcat(fViewMatrix);
boundsMatrix.mapRect(outBounds);
// Due to floating point numerical inaccuracies, we have to round out here
outBounds->roundOut(outBounds);
}
}
const SkMatrix& viewMatrix() const { return fViewMatrix; }
// position + local coord // position + local coord
static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16); static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16);
static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16); static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16);
@ -221,12 +255,6 @@ public:
this->setupViewMatrix(viewMatrix, x, y); this->setupViewMatrix(viewMatrix, x, y);
} }
GrDrawBatch* test_createBatch(int glyphCount, int run, int subRun,
GrColor color, SkScalar transX, SkScalar transY,
const SkPaint& skPaint, const SkSurfaceProps& props,
const GrDistanceFieldAdjustTable* distanceAdjustTable,
GrBatchFontCache* cache);
const Key& key() const { return fKey; } const Key& key() const { return fKey; }
~GrAtlasTextBlob() { ~GrAtlasTextBlob() {
@ -235,6 +263,14 @@ public:
} }
} }
////////////////////////////////////////////////////////////////////////////////////////////////
// Internal test methods
GrDrawBatch* test_createBatch(int glyphCount, int run, int subRun,
GrColor color, SkScalar transX, SkScalar transY,
const SkPaint& skPaint, const SkSurfaceProps& props,
const GrDistanceFieldAdjustTable* distanceAdjustTable,
GrBatchFontCache* cache);
private: private:
GrAtlasTextBlob() GrAtlasTextBlob()
: fMaxMinScale(-SK_ScalarMax) : fMaxMinScale(-SK_ScalarMax)