Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: src/gpu/GrBitmapTextContext.cpp

Issue 510103003: Revert of Restore text alloc optimizations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrBitmapTextContext.h ('k') | src/gpu/GrDistanceFieldTextContext.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrBitmapTextContext.cpp
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index c992b9527f9202252e3fe31c7d94d0b96a00d0b2..0c4d324d895b49ffb5236cfa86183830082a3229 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -51,12 +51,16 @@
GrBitmapTextContext::GrBitmapTextContext(GrContext* context,
const SkDeviceProperties& properties)
- : GrTextContext(context, properties)
- , fStrike(NULL)
- , fEffectTextureUniqueID(SK_InvalidUniqueID)
- , fVertices(NULL)
- , fVertexCount(0)
- , fCurrVertex(0) {
+ : GrTextContext(context, properties) {
+ fStrike = NULL;
+
+ fCurrTexture = NULL;
+ fCurrVertex = 0;
+ fEffectTextureUniqueID = SK_InvalidUniqueID;
+
+ fVertices = NULL;
+ fMaxVertices = 0;
+
fVertexBounds.setLargestInverted();
}
@@ -87,14 +91,13 @@
if (fCurrVertex > 0) {
// setup our sampler state for our text texture/atlas
SkASSERT(SkIsAlign4(fCurrVertex));
+ SkASSERT(fCurrTexture);
GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNone_FilterMode);
- GrTexture* currTexture = fStrike->getTexture();
- SkASSERT(currTexture);
- uint32_t textureUniqueID = currTexture->getUniqueID();
+ uint32_t textureUniqueID = fCurrTexture->getUniqueID();
if (textureUniqueID != fEffectTextureUniqueID) {
- fCachedEffect.reset(GrCustomCoordsTextureEffect::Create(currTexture, params));
+ fCachedEffect.reset(GrCustomCoordsTextureEffect::Create(fCurrTexture, params));
fEffectTextureUniqueID = textureUniqueID;
}
@@ -146,13 +149,14 @@
fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
nGlyphs,
4, 6, &fVertexBounds);
- fVertexCount = 0;
+
+ fDrawTarget->resetVertexSource();
+ fVertices = NULL;
+ fMaxVertices = 0;
fCurrVertex = 0;
fVertexBounds.setLargestInverted();
- }
-
- fDrawTarget->resetVertexSource();
- fVertices = NULL;
+ SkSafeSetNull(fCurrTexture);
+ }
}
inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPaint) {
@@ -160,33 +164,17 @@
fStrike = NULL;
+ fCurrTexture = NULL;
+ fCurrVertex = 0;
+
fVertices = NULL;
- fVertexCount = 0;
- fCurrVertex = 0;
+ fMaxVertices = 0;
}
inline void GrBitmapTextContext::finish() {
this->flushGlyphs();
GrTextContext::finish();
-}
-
-void GrBitmapTextContext::allocateVertices(const char text[], size_t byteLength) {
- SkASSERT(NULL == fVertices);
- bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
- if (useColorVerts) {
- fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>(
- SK_ARRAY_COUNT(gTextVertexWithColorAttribs));
- } else {
- fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
- SK_ARRAY_COUNT(gTextVertexAttribs));
- }
- fVertexCount = 4*fSkPaint.textToGlyphs(text, byteLength, NULL);
- bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount,
- 0,
- &fVertices,
- NULL);
- GrAlwaysAssert(success);
}
void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
@@ -200,20 +188,13 @@
}
this->init(paint, skPaint);
-
- if (NULL == fDrawTarget) {
- return;
- }
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMatrix());
SkGlyphCache* cache = autoCache.getCache();
GrFontScaler* fontScaler = GetGrFontScaler(cache);
- if (NULL == fStrike) {
- fStrike = fContext->getFontCache()->getStrike(fontScaler, false);
- }
-
+
// transform our starting point
{
SkPoint loc;
@@ -241,7 +222,7 @@
const char* stop = text + byteLength;
- this->allocateVertices(text, byteLength);
+ SkAutoKern autokern;
SkFixed fxMask = ~0;
SkFixed fyMask = ~0;
@@ -266,7 +247,6 @@
GrContext::AutoMatrix autoMatrix;
autoMatrix.setIdentity(fContext, &fPaint);
- SkAutoKern autokern;
while (text < stop) {
const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask);
@@ -302,25 +282,16 @@
this->init(paint, skPaint);
- if (NULL == fDrawTarget) {
- return;
- }
-
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMatrix());
SkGlyphCache* cache = autoCache.getCache();
GrFontScaler* fontScaler = GetGrFontScaler(cache);
- if (NULL == fStrike) {
- fStrike = fContext->getFontCache()->getStrike(fontScaler, false);
- }
// store original matrix before we reset, so we can use it to transform positions
SkMatrix ctm = fContext->getMatrix();
GrContext::AutoMatrix autoMatrix;
autoMatrix.setIdentity(fContext, &fPaint);
-
- this->allocateVertices(text, byteLength);
const char* stop = text + byteLength;
SkTextAlignProc alignProc(fSkPaint.getTextAlign());
@@ -453,6 +424,14 @@
void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
SkFixed vx, SkFixed vy,
GrFontScaler* scaler) {
+ if (NULL == fDrawTarget) {
+ return;
+ }
+
+ if (NULL == fStrike) {
+ fStrike = fContext->getFontCache()->getStrike(scaler, false);
+ }
+
GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
if (NULL == glyph || glyph->fBounds.isEmpty()) {
return;
@@ -493,17 +472,8 @@
}
// flush any accumulated draws to allow us to free up a plot
- int remainingVertexCount = fVertexCount - fCurrVertex;
this->flushGlyphs();
fContext->flush();
-
- // need to reallocate the vertex buffer for the remaining glyphs
- fVertexCount = remainingVertexCount;
- bool success = fDrawTarget->reserveVertexAndIndexSpace(fVertexCount,
- 0,
- &fVertices,
- NULL);
- GrAlwaysAssert(success);
// we should have an unused plot now
if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
@@ -544,6 +514,55 @@
GrTexture* texture = glyph->fPlot->texture();
SkASSERT(texture);
+ if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) {
+ this->flushGlyphs();
+ fCurrTexture = texture;
+ fCurrTexture->ref();
+ }
+
+ bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
+
+ if (NULL == fVertices) {
+ // If we need to reserve vertices allow the draw target to suggest
+ // a number of verts to reserve and whether to perform a flush.
+ fMaxVertices = kMinRequestedVerts;
+ if (useColorVerts) {
+ fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>(
+ SK_ARRAY_COUNT(gTextVertexWithColorAttribs));
+ } else {
+ fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
+ SK_ARRAY_COUNT(gTextVertexAttribs));
+ }
+ bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
+ if (flush) {
+ this->flushGlyphs();
+ fContext->flush();
+ if (useColorVerts) {
+ fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttribs>(
+ SK_ARRAY_COUNT(gTextVertexWithColorAttribs));
+ } else {
+ fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
+ SK_ARRAY_COUNT(gTextVertexAttribs));
+ }
+ }
+ fMaxVertices = kDefaultRequestedVerts;
+ // ignore return, no point in flushing again.
+ fDrawTarget->geometryHints(&fMaxVertices, NULL);
+
+ int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads();
+ if (fMaxVertices < kMinRequestedVerts) {
+ fMaxVertices = kDefaultRequestedVerts;
+ } else if (fMaxVertices > maxQuadVertices) {
+ // don't exceed the limit of the index buffer
+ fMaxVertices = maxQuadVertices;
+ }
+ bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices,
+ 0,
+ &fVertices,
+ NULL);
+ GrAlwaysAssert(success);
+ }
+
SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX);
SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY);
@@ -555,7 +574,6 @@
fVertexBounds.growToInclude(r);
- bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) :
(2 * sizeof(SkPoint));
« no previous file with comments | « src/gpu/GrBitmapTextContext.h ('k') | src/gpu/GrDistanceFieldTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698