| Index: src/gpu/GrDistanceFieldTextContext.cpp
|
| diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
|
| index 4c9631e1462cbbaeee4b4e9d0b6f757d06a1633b..9fa0590e0b1839447f23bab089903bd171b4d833 100755
|
| --- a/src/gpu/GrDistanceFieldTextContext.cpp
|
| +++ b/src/gpu/GrDistanceFieldTextContext.cpp
|
| @@ -13,6 +13,7 @@
|
| #include "GrIndexBuffer.h"
|
| #include "GrTextStrike.h"
|
| #include "GrTextStrike_impl.h"
|
| +#include "SkGpuDevice.h"
|
| #include "SkPath.h"
|
| #include "SkRTConf.h"
|
| #include "SkStrokeRec.h"
|
| @@ -25,10 +26,10 @@ static const int kBaseDFFontSize = 32;
|
| SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
|
| "Dump the contents of the font cache before every purge.");
|
|
|
| -GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
|
| +GrDistanceFieldTextContext::GrDistanceFieldTextContext(SkGpuDevice* device,
|
| const GrPaint& grPaint,
|
| const SkPaint& skPaint)
|
| - : GrTextContext(context, grPaint, skPaint) {
|
| + : GrTextContext(device, grPaint, skPaint) {
|
| fStrike = NULL;
|
|
|
| fCurrTexture = NULL;
|
| @@ -61,9 +62,10 @@ void GrDistanceFieldTextContext::flushGlyphs() {
|
| return;
|
| }
|
|
|
| + GrContext* context = fDevice->context();
|
| GrDrawState* drawState = fDrawTarget->drawState();
|
| GrDrawState::AutoRestoreEffects are(drawState);
|
| - drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTarget());
|
| + drawState->setFromPaint(fPaint, context->getMatrix(), context->getRenderTarget());
|
|
|
| if (fCurrVertex > 0) {
|
| // setup our sampler state for our text texture/atlas
|
| @@ -99,7 +101,7 @@ void GrDistanceFieldTextContext::flushGlyphs() {
|
| }
|
|
|
| int nGlyphs = fCurrVertex / 4;
|
| - fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
|
| + fDrawTarget->setIndexSourceToBuffer(context->getQuadIndexBuffer());
|
| fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
|
| nGlyphs,
|
| 4, 6);
|
| @@ -127,8 +129,9 @@ void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
| if (NULL == fDrawTarget) {
|
| return;
|
| }
|
| + GrContext* context = fDevice->context();
|
| if (NULL == fStrike) {
|
| - fStrike = fContext->getFontCache()->getStrike(scaler, true);
|
| + fStrike = context->getFontCache()->getStrike(scaler, true);
|
| }
|
|
|
| GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
|
| @@ -163,23 +166,23 @@ void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
| }
|
|
|
| // try to clear out an unused plot before we flush
|
| - fContext->getFontCache()->freePlotExceptFor(fStrike);
|
| + context->getFontCache()->freePlotExceptFor(fStrike);
|
| if (fStrike->getGlyphAtlas(glyph, scaler)) {
|
| goto HAS_ATLAS;
|
| }
|
|
|
| if (c_DumpFontCache) {
|
| #ifdef SK_DEVELOPER
|
| - fContext->getFontCache()->dump();
|
| + context->getFontCache()->dump();
|
| #endif
|
| }
|
|
|
| // before we purge the cache, we must flush any accumulated draws
|
| this->flushGlyphs();
|
| - fContext->flush();
|
| + context->flush();
|
|
|
| // try to purge
|
| - fContext->getFontCache()->purgeExceptFor(fStrike);
|
| + context->getFontCache()->purgeExceptFor(fStrike);
|
| // need to use new flush count here
|
| if (fStrike->getGlyphAtlas(glyph, scaler)) {
|
| goto HAS_ATLAS;
|
| @@ -199,9 +202,9 @@ void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
| SkMatrix translate;
|
| translate.setTranslate(sx, sy);
|
| GrPaint tmpPaint(fPaint);
|
| - am.setPreConcat(fContext, translate, &tmpPaint);
|
| + am.setPreConcat(context, translate, &tmpPaint);
|
| SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
|
| - fContext->drawPath(tmpPaint, *glyph->fPath, stroke);
|
| + context->drawPath(tmpPaint, *glyph->fPath, stroke);
|
| return;
|
| }
|
|
|
| @@ -228,7 +231,7 @@ HAS_ATLAS:
|
| bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
|
| if (flush) {
|
| this->flushGlyphs();
|
| - fContext->flush();
|
| + context->flush();
|
| fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>(
|
| SK_ARRAY_COUNT(gTextVertexAttribs));
|
| }
|
| @@ -236,7 +239,7 @@ HAS_ATLAS:
|
| // ignore return, no point in flushing again.
|
| fDrawTarget->geometryHints(&fMaxVertices, NULL);
|
|
|
| - int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads();
|
| + int maxQuadVertices = 4 * context->getQuadIndexBuffer()->maxQuads();
|
| if (fMaxVertices < kMinRequestedVerts) {
|
| fMaxVertices = kDefaultRequestedVerts;
|
| } else if (fMaxVertices > maxQuadVertices) {
|
| @@ -283,19 +286,23 @@ HAS_ATLAS:
|
| }
|
|
|
| void GrDistanceFieldTextContext::drawText(const char text[], size_t byteLength,
|
| - SkScalar x, SkScalar y, SkGlyphCache* cache,
|
| - GrFontScaler* fontScaler) {
|
| + SkScalar x, SkScalar y) {
|
| SkASSERT(byteLength == 0 || text != NULL);
|
|
|
| - // nothing to draw
|
| - if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) {
|
| + // nothing to draw or can't draw
|
| + if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/
|
| + || fSkPaint.getRasterizer()) {
|
| return;
|
| }
|
| -
|
| +
|
| SkScalar sizeRatio = fTextRatio;
|
|
|
| SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
|
|
|
| + SkAutoGlyphCache autoCache(fSkPaint, &fDevice->getDeviceProperties(), NULL);
|
| + SkGlyphCache* cache = autoCache.getCache();
|
| + GrFontScaler* fontScaler = GetGrFontScaler(cache);
|
| +
|
| // need to measure first
|
| // TODO - generate positions and pre-load cache as well?
|
| const char* stop = text + byteLength;
|
| @@ -348,19 +355,23 @@ void GrDistanceFieldTextContext::drawText(const char text[], size_t byteLength,
|
|
|
| void GrDistanceFieldTextContext::drawPosText(const char text[], size_t byteLength,
|
| const SkScalar pos[], SkScalar constY,
|
| - int scalarsPerPosition,
|
| - SkGlyphCache* cache, GrFontScaler* fontScaler) {
|
| + int scalarsPerPosition) {
|
|
|
| SkASSERT(byteLength == 0 || text != NULL);
|
| SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
|
|
|
| // nothing to draw
|
| - if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) {
|
| + if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/
|
| + || fSkPaint.getRasterizer()) {
|
| return;
|
| }
|
|
|
| SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
|
|
|
| + SkAutoGlyphCache autoCache(fSkPaint, &fDevice->getDeviceProperties(), NULL);
|
| + SkGlyphCache* cache = autoCache.getCache();
|
| + GrFontScaler* fontScaler = GetGrFontScaler(cache);
|
| +
|
| const char* stop = text + byteLength;
|
|
|
| if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) {
|
|
|