Revert of Restore text alloc optimizations. (patchset #4 of https://codereview.chromium.org/466363009/)
Reason for revert: GM failures on http://108.170.220.120:10115/builders/Test-Ubuntu12-ShuttleA-GTX660-x86-Release/builds/1867/ Original issue's description: > Restore text vertex buffer alloc and other optimizations. > > Modifies the fontcache GM to ensure that the font cache is forced to flush. > > Committed: https://skia.googlesource.com/skia/+/9c3d24b9d1ba3d955094ff0cb1ba2d11e1c1adca R=bsalomon@google.com, robertphillips@google.com, jvanverth@google.com TBR=bsalomon@google.com, jvanverth@google.com, robertphillips@google.com NOTREECHECKS=true NOTRY=true Author: djsollen@google.com Review URL: https://codereview.chromium.org/510103003
This commit is contained in:
parent
ea81ced1e5
commit
2e1a82675c
@ -55,6 +55,3 @@ filterbitmap_image_mandrill_32.png
|
||||
filterbitmap_image_mandrill_64.png
|
||||
filterbitmap_text_3.00pt
|
||||
filterbitmap_text_7.00pt
|
||||
|
||||
# Added as part of https://codereview.chromium.org/466363009/
|
||||
fontcache
|
||||
|
@ -13,15 +13,15 @@
|
||||
// GM to stress the GPU font cache
|
||||
|
||||
const char* gFamilyNames[] = {
|
||||
"sans-serif", "serif"
|
||||
"sans-serif", "serif", "monospace"
|
||||
};
|
||||
|
||||
const SkTypeface::Style gStyles[] = {
|
||||
SkTypeface::kNormal, SkTypeface::kItalic, SkTypeface::kBold
|
||||
SkTypeface::kNormal, SkTypeface::kItalic
|
||||
};
|
||||
|
||||
const SkScalar gTextSizes[] = {
|
||||
192, 194, 196, 198, 200, 202, 204, 206
|
||||
12, 14, 16, 18, 20, 22, 24, 26, 28, 30
|
||||
};
|
||||
|
||||
#define TYPEFACE_COUNT (SK_ARRAY_COUNT(gFamilyNames)*SK_ARRAY_COUNT(gStyles))
|
||||
@ -52,7 +52,7 @@ protected:
|
||||
}
|
||||
|
||||
virtual SkISize onISize() SK_OVERRIDE {
|
||||
return SkISize::Make(1280, 640);
|
||||
return SkISize::Make(640, 320);
|
||||
}
|
||||
|
||||
virtual void onOnceBeforeDraw() SK_OVERRIDE {
|
||||
@ -72,19 +72,35 @@ protected:
|
||||
paint.setLCDRenderText(true);
|
||||
paint.setSubpixelText(true);
|
||||
|
||||
SkString text("H");
|
||||
SkString text("Ham");
|
||||
|
||||
// draw enough to overflow the cache
|
||||
// draw some initial text to partially fill the GPU cache
|
||||
for (size_t i = 0; i < 2; ++i) {
|
||||
paint.setTypeface(fTypefaces[i]);
|
||||
SkScalar x = 20;
|
||||
|
||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) {
|
||||
paint.setTextSize(gTextSizes[j]);
|
||||
x = draw_string(canvas, text, x, y, paint) + 19;
|
||||
}
|
||||
y += 32;
|
||||
}
|
||||
|
||||
// force a flush
|
||||
canvas->flush();
|
||||
|
||||
// draw again, and more to overflow the cache
|
||||
for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
|
||||
paint.setTypeface(fTypefaces[i]);
|
||||
SkScalar x = 20;
|
||||
|
||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) {
|
||||
paint.setTextSize(gTextSizes[j]);
|
||||
x = draw_string(canvas, text, x, y, paint) + 10;
|
||||
x = draw_string(canvas, text, x, y, paint) + 19;
|
||||
}
|
||||
y += 128;
|
||||
y += 32;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual uint32_t onGetFlags() const SK_OVERRIDE {
|
||||
|
@ -51,12 +51,16 @@ extern const GrVertexAttrib gTextVertexWithColorAttribs[] = {
|
||||
|
||||
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 @@ void GrBitmapTextContext::flushGlyphs() {
|
||||
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 @@ void GrBitmapTextContext::flushGlyphs() {
|
||||
fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
|
||||
nGlyphs,
|
||||
4, 6, &fVertexBounds);
|
||||
fVertexCount = 0;
|
||||
|
||||
fDrawTarget->resetVertexSource();
|
||||
fVertices = NULL;
|
||||
fMaxVertices = 0;
|
||||
fCurrVertex = 0;
|
||||
fVertexBounds.setLargestInverted();
|
||||
SkSafeSetNull(fCurrTexture);
|
||||
}
|
||||
|
||||
fDrawTarget->resetVertexSource();
|
||||
fVertices = NULL;
|
||||
}
|
||||
|
||||
inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPaint) {
|
||||
@ -160,9 +164,11 @@ inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai
|
||||
|
||||
fStrike = NULL;
|
||||
|
||||
fVertices = NULL;
|
||||
fVertexCount = 0;
|
||||
fCurrTexture = NULL;
|
||||
fCurrVertex = 0;
|
||||
|
||||
fVertices = NULL;
|
||||
fMaxVertices = 0;
|
||||
}
|
||||
|
||||
inline void GrBitmapTextContext::finish() {
|
||||
@ -171,24 +177,6 @@ inline void GrBitmapTextContext::finish() {
|
||||
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,
|
||||
const char text[], size_t byteLength,
|
||||
SkScalar x, SkScalar y) {
|
||||
@ -200,20 +188,13 @@ void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
|
||||
}
|
||||
|
||||
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 @@ void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
|
||||
|
||||
const char* stop = text + byteLength;
|
||||
|
||||
this->allocateVertices(text, byteLength);
|
||||
SkAutoKern autokern;
|
||||
|
||||
SkFixed fxMask = ~0;
|
||||
SkFixed fyMask = ~0;
|
||||
@ -266,7 +247,6 @@ void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
|
||||
GrContext::AutoMatrix autoMatrix;
|
||||
autoMatrix.setIdentity(fContext, &fPaint);
|
||||
|
||||
SkAutoKern autokern;
|
||||
while (text < stop) {
|
||||
const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask);
|
||||
|
||||
@ -302,26 +282,17 @@ void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPai
|
||||
|
||||
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());
|
||||
SkTextMapStateProc tmsProc(ctm, constY, scalarsPerPosition);
|
||||
@ -453,6 +424,14 @@ void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPai
|
||||
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,18 +472,9 @@ void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
||||
}
|
||||
|
||||
// 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) &&
|
||||
fStrike->addGlyphToAtlas(glyph, scaler)) {
|
||||
@ -544,6 +514,55 @@ HAS_ATLAS:
|
||||
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 @@ HAS_ATLAS:
|
||||
|
||||
fVertexBounds.growToInclude(r);
|
||||
|
||||
bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
|
||||
size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) :
|
||||
(2 * sizeof(SkPoint));
|
||||
|
||||
|
@ -30,8 +30,9 @@ public:
|
||||
virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
GrTextStrike* fStrike;
|
||||
|
||||
void init(const GrPaint&, const SkPaint&);
|
||||
void allocateVertices(const char text[], size_t byteLength);
|
||||
void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
|
||||
void flushGlyphs(); // automatically called by destructor
|
||||
void finish();
|
||||
@ -43,13 +44,12 @@ private:
|
||||
kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
|
||||
};
|
||||
|
||||
GrTextStrike* fStrike;
|
||||
void* fVertices;
|
||||
int32_t fMaxVertices;
|
||||
GrTexture* fCurrTexture;
|
||||
SkAutoTUnref<GrEffect> fCachedEffect;
|
||||
// Used to check whether fCachedEffect is still valid.
|
||||
uint32_t fEffectTextureUniqueID;
|
||||
|
||||
void* fVertices;
|
||||
int fVertexCount;
|
||||
int fCurrVertex;
|
||||
SkRect fVertexBounds;
|
||||
};
|
||||
|
@ -56,20 +56,24 @@ extern const GrVertexAttrib gTextVertexWithColorAttribs[] = {
|
||||
GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
|
||||
const SkDeviceProperties& properties,
|
||||
bool enable)
|
||||
: GrTextContext(context, properties)
|
||||
, fStrike(NULL)
|
||||
: GrTextContext(context, properties) {
|
||||
#if SK_FORCE_DISTANCEFIELD_FONTS
|
||||
, fEnableDFRendering(true)
|
||||
fEnableDFRendering = true;
|
||||
#else
|
||||
, fEnableDFRendering(true)//enable)
|
||||
fEnableDFRendering = enable;
|
||||
#endif
|
||||
, fEffectTextureUniqueID(SK_InvalidUniqueID)
|
||||
, fEffectColor(GrColor_ILLEGAL)
|
||||
, fEffectFlags(0)
|
||||
, fGammaTexture(NULL)
|
||||
, fVertices(NULL)
|
||||
, fVertexCount(0)
|
||||
, fCurrVertex(0) {
|
||||
fStrike = NULL;
|
||||
fGammaTexture = NULL;
|
||||
|
||||
fCurrTexture = NULL;
|
||||
fCurrVertex = 0;
|
||||
fEffectTextureUniqueID = SK_InvalidUniqueID;
|
||||
fEffectColor = GrColor_ILLEGAL;
|
||||
fEffectFlags = 0;
|
||||
|
||||
fVertices = NULL;
|
||||
fMaxVertices = 0;
|
||||
|
||||
fVertexBounds.setLargestInverted();
|
||||
}
|
||||
|
||||
@ -118,9 +122,7 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo
|
||||
GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode);
|
||||
GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode);
|
||||
|
||||
GrTexture* currTexture = fStrike->getTexture();
|
||||
SkASSERT(currTexture);
|
||||
uint32_t textureUniqueID = currTexture->getUniqueID();
|
||||
uint32_t textureUniqueID = fCurrTexture->getUniqueID();
|
||||
|
||||
// set up any flags
|
||||
uint32_t flags = 0;
|
||||
@ -138,7 +140,7 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo
|
||||
flags != fEffectFlags) {
|
||||
if (fUseLCDText) {
|
||||
GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor);
|
||||
fCachedEffect.reset(GrDistanceFieldLCDTextureEffect::Create(currTexture,
|
||||
fCachedEffect.reset(GrDistanceFieldLCDTextureEffect::Create(fCurrTexture,
|
||||
params,
|
||||
fGammaTexture,
|
||||
gammaParams,
|
||||
@ -148,7 +150,7 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo
|
||||
#ifdef SK_GAMMA_APPLY_TO_A8
|
||||
U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDeviceProperties.fGamma,
|
||||
filteredColor);
|
||||
fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(currTexture,
|
||||
fCachedEffect.reset(GrDistanceFieldTextureEffect::Create(fCurrTexture,
|
||||
params,
|
||||
fGammaTexture,
|
||||
gammaParams,
|
||||
@ -224,17 +226,26 @@ void GrDistanceFieldTextContext::flushGlyphs() {
|
||||
fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
|
||||
nGlyphs,
|
||||
4, 6, &fVertexBounds);
|
||||
fDrawTarget->resetVertexSource();
|
||||
fVertices = NULL;
|
||||
fMaxVertices = 0;
|
||||
fCurrVertex = 0;
|
||||
SkSafeSetNull(fCurrTexture);
|
||||
fVertexBounds.setLargestInverted();
|
||||
}
|
||||
|
||||
fDrawTarget->resetVertexSource();
|
||||
fVertices = NULL;
|
||||
}
|
||||
|
||||
void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
||||
SkFixed vx, SkFixed vy,
|
||||
GrFontScaler* scaler) {
|
||||
if (NULL == fDrawTarget) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (NULL == fStrike) {
|
||||
fStrike = fContext->getFontCache()->getStrike(scaler, true);
|
||||
}
|
||||
|
||||
GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
|
||||
if (NULL == glyph || glyph->fBounds.isEmpty()) {
|
||||
return;
|
||||
@ -278,19 +289,10 @@ void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
||||
#endif
|
||||
}
|
||||
|
||||
// flush any accumulated draws to allow us to free up a plot
|
||||
int remainingVertexCount = fVertexCount - fCurrVertex;
|
||||
// before we purge the cache, we must flush any accumulated draws
|
||||
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) &&
|
||||
fStrike->addGlyphToAtlas(glyph, scaler)) {
|
||||
@ -326,6 +328,55 @@ HAS_ATLAS:
|
||||
GrTexture* texture = glyph->fPlot->texture();
|
||||
SkASSERT(texture);
|
||||
|
||||
if (fCurrTexture != texture || fCurrVertex + 4 > fMaxVertices) {
|
||||
this->flushGlyphs();
|
||||
fCurrTexture = texture;
|
||||
fCurrTexture->ref();
|
||||
}
|
||||
|
||||
bool useColorVerts = !fUseLCDText;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset);
|
||||
SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset);
|
||||
SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldInset);
|
||||
@ -338,7 +389,7 @@ HAS_ATLAS:
|
||||
sy += dy;
|
||||
width *= scale;
|
||||
height *= scale;
|
||||
|
||||
|
||||
SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX + SK_DistanceFieldInset);
|
||||
SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY + SK_DistanceFieldInset);
|
||||
SkFixed tw = SkIntToFixed(glyph->fBounds.width() - 2*SK_DistanceFieldInset);
|
||||
@ -369,7 +420,7 @@ HAS_ATLAS:
|
||||
SkFixedToFloat(texture->normalizeFixedX(tx + tw)),
|
||||
SkFixedToFloat(texture->normalizeFixedY(ty + th)),
|
||||
vertSize);
|
||||
if (!fUseLCDText) {
|
||||
if (useColorVerts) {
|
||||
if (0xFF == GrColorUnpackA(fPaint.getColor())) {
|
||||
fDrawTarget->drawState()->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true);
|
||||
}
|
||||
@ -459,23 +510,6 @@ static void setup_gamma_texture(GrContext* context, const SkGlyphCache* cache,
|
||||
}
|
||||
}
|
||||
|
||||
void GrDistanceFieldTextContext::allocateVertices(const char text[], size_t byteLength) {
|
||||
SkASSERT(NULL == fVertices);
|
||||
if (!fUseLCDText) {
|
||||
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 GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
|
||||
const char text[], size_t byteLength,
|
||||
SkScalar x, SkScalar y) {
|
||||
@ -489,10 +523,6 @@ void GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& s
|
||||
|
||||
this->init(paint, skPaint);
|
||||
|
||||
if (NULL == fDrawTarget) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkScalar sizeRatio = fTextRatio;
|
||||
|
||||
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
|
||||
@ -500,14 +530,9 @@ void GrDistanceFieldTextContext::drawText(const GrPaint& paint, const SkPaint& s
|
||||
SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL);
|
||||
SkGlyphCache* cache = autoCache.getCache();
|
||||
GrFontScaler* fontScaler = GetGrFontScaler(cache);
|
||||
if (NULL == fStrike) {
|
||||
fStrike = fContext->getFontCache()->getStrike(fontScaler, true);
|
||||
}
|
||||
|
||||
setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture);
|
||||
|
||||
this->allocateVertices(text, byteLength);
|
||||
|
||||
// need to measure first
|
||||
// TODO - generate positions and pre-load cache as well?
|
||||
const char* stop = text + byteLength;
|
||||
@ -575,23 +600,14 @@ void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint
|
||||
|
||||
this->init(paint, skPaint);
|
||||
|
||||
if (NULL == fDrawTarget) {
|
||||
return;
|
||||
}
|
||||
|
||||
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
|
||||
|
||||
SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL);
|
||||
SkGlyphCache* cache = autoCache.getCache();
|
||||
GrFontScaler* fontScaler = GetGrFontScaler(cache);
|
||||
if (NULL == fStrike) {
|
||||
fStrike = fContext->getFontCache()->getStrike(fontScaler, true);
|
||||
}
|
||||
|
||||
setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture);
|
||||
|
||||
this->allocateVertices(text, byteLength);
|
||||
|
||||
const char* stop = text + byteLength;
|
||||
|
||||
if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) {
|
||||
|
@ -30,8 +30,18 @@ public:
|
||||
virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
GrTextStrike* fStrike;
|
||||
SkScalar fTextRatio;
|
||||
bool fUseLCDText;
|
||||
bool fEnableDFRendering;
|
||||
SkAutoTUnref<GrEffect> fCachedEffect;
|
||||
// Used to check whether fCachedEffect is still valid.
|
||||
uint32_t fEffectTextureUniqueID;
|
||||
SkColor fEffectColor;
|
||||
uint32_t fEffectFlags;
|
||||
GrTexture* fGammaTexture;
|
||||
|
||||
void init(const GrPaint&, const SkPaint&);
|
||||
void allocateVertices(const char text[], size_t byteLength);
|
||||
void drawPackedGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
|
||||
void flushGlyphs(); // automatically called by destructor
|
||||
void setupCoverageEffect(const SkColor& filteredColor);
|
||||
@ -44,19 +54,9 @@ private:
|
||||
kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
|
||||
};
|
||||
|
||||
GrTextStrike* fStrike;
|
||||
SkScalar fTextRatio;
|
||||
bool fUseLCDText;
|
||||
bool fEnableDFRendering;
|
||||
SkAutoTUnref<GrEffect> fCachedEffect;
|
||||
// Used to check whether fCachedEffect is still valid.
|
||||
uint32_t fEffectTextureUniqueID;
|
||||
SkColor fEffectColor;
|
||||
uint32_t fEffectFlags;
|
||||
GrTexture* fGammaTexture;
|
||||
|
||||
void* fVertices;
|
||||
int fVertexCount;
|
||||
int32_t fMaxVertices;
|
||||
GrTexture* fCurrTexture;
|
||||
int fCurrVertex;
|
||||
SkRect fVertexBounds;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user