| Index: src/gpu/GrDistanceFieldTextContext.cpp
|
| diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
|
| similarity index 76%
|
| copy from src/gpu/GrBitmapTextContext.cpp
|
| copy to src/gpu/GrDistanceFieldTextContext.cpp
|
| index 7a99f093e5149108163a402a2aa9ee7788dc1f47..1b0fa21355bd2152a455f3a0b3f6f9a973b46c3a 100755
|
| --- a/src/gpu/GrBitmapTextContext.cpp
|
| +++ b/src/gpu/GrDistanceFieldTextContext.cpp
|
| @@ -5,7 +5,7 @@
|
| * found in the LICENSE file.
|
| */
|
|
|
| -#include "GrBitmapTextContext.h"
|
| +#include "GrDistanceFieldTextContext.h"
|
| #include "GrAtlas.h"
|
| #include "GrDrawTarget.h"
|
| #include "GrFontScaler.h"
|
| @@ -15,17 +15,19 @@
|
| #include "SkPath.h"
|
| #include "SkRTConf.h"
|
| #include "SkStrokeRec.h"
|
| -#include "effects/GrCustomCoordsTextureEffect.h"
|
| +#include "effects/GrDistanceFieldTextureEffect.h"
|
|
|
| static const int kGlyphCoordsAttributeIndex = 1;
|
|
|
| SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
|
| "Dump the contents of the font cache before every purge.");
|
|
|
| -GrBitmapTextContext::GrBitmapTextContext(GrContext* context, const GrPaint& paint) :
|
| - GrTextContext(context, paint) {
|
| - fAutoMatrix.setIdentity(fContext, &fPaint);
|
|
|
| +GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context,
|
| + const GrPaint& paint,
|
| + SkScalar textSize) :
|
| + GrTextContext(context, paint),
|
| + fTextSize(textSize) {
|
| fStrike = NULL;
|
|
|
| fCurrTexture = NULL;
|
| @@ -35,28 +37,31 @@ GrBitmapTextContext::GrBitmapTextContext(GrContext* context, const GrPaint& pain
|
| fMaxVertices = 0;
|
| }
|
|
|
| -GrBitmapTextContext::~GrBitmapTextContext() {
|
| +GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
|
| this->flushGlyphs();
|
| }
|
|
|
| -void GrBitmapTextContext::flushGlyphs() {
|
| +void GrDistanceFieldTextContext::flushGlyphs() {
|
| if (NULL == fDrawTarget) {
|
| return;
|
| }
|
|
|
| GrDrawState* drawState = fDrawTarget->drawState();
|
| GrDrawState::AutoRestoreEffects are(drawState);
|
| - drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget());
|
| + SkMatrix transform;
|
| + transform.reset();
|
| + transform = fContext->getMatrix();
|
| + drawState->setFromPaint(fPaint, transform, fContext->getRenderTarget());
|
|
|
| if (fCurrVertex > 0) {
|
| // setup our sampler state for our text texture/atlas
|
| SkASSERT(GrIsALIGN4(fCurrVertex));
|
| SkASSERT(fCurrTexture);
|
| - GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNone_FilterMode);
|
| + GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBilerp_FilterMode);
|
|
|
| // This effect could be stored with one of the cache objects (atlas?)
|
| drawState->addCoverageEffect(
|
| - GrCustomCoordsTextureEffect::Create(fCurrTexture, params),
|
| + GrDistanceFieldTextureEffect::Create(fCurrTexture, params),
|
| kGlyphCoordsAttributeIndex)->unref();
|
|
|
| if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
|
| @@ -100,14 +105,14 @@ extern const GrVertexAttrib gTextVertexAttribs[] = {
|
|
|
| };
|
|
|
| -void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
| - GrFixed vx, GrFixed vy,
|
| - GrFontScaler* scaler) {
|
| +void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
| + GrFixed vx, GrFixed vy,
|
| + GrFontScaler* scaler) {
|
| if (NULL == fDrawTarget) {
|
| return;
|
| }
|
| if (NULL == fStrike) {
|
| - fStrike = fContext->getFontCache()->getStrike(scaler);
|
| + fStrike = fContext->getFontCache()->getStrike(scaler, true);
|
| }
|
|
|
| GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
|
| @@ -115,9 +120,13 @@ void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
| return;
|
| }
|
|
|
| + SkScalar sx = SkFixedToScalar(vx);
|
| + SkScalar sy = SkFixedToScalar(vy);
|
| +/*
|
| + // not valid, need to find a different solution for this
|
| vx += SkIntToFixed(glyph->fBounds.fLeft);
|
| vy += SkIntToFixed(glyph->fBounds.fTop);
|
| -
|
| +
|
| // keep them as ints until we've done the clip-test
|
| GrFixed width = glyph->fBounds.width();
|
| GrFixed height = glyph->fBounds.height();
|
| @@ -131,7 +140,7 @@ void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
| return;
|
| }
|
| }
|
| -
|
| +*/
|
| if (NULL == glyph->fPlot) {
|
| if (fStrike->getGlyphAtlas(glyph, scaler)) {
|
| goto HAS_ATLAS;
|
| @@ -172,8 +181,7 @@ void GrBitmapTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
|
|
|
| GrContext::AutoMatrix am;
|
| SkMatrix translate;
|
| - translate.setTranslate(SkFixedToScalar(vx - SkIntToFixed(glyph->fBounds.fLeft)),
|
| - SkFixedToScalar(vy - SkIntToFixed(glyph->fBounds.fTop)));
|
| + translate.setTranslate(sx, sy);
|
| GrPaint tmpPaint(fPaint);
|
| am.setPreConcat(fContext, translate, &tmpPaint);
|
| SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
|
| @@ -186,10 +194,6 @@ HAS_ATLAS:
|
| GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken();
|
| glyph->fPlot->setDrawToken(drawToken);
|
|
|
| - // now promote them to fixed (TODO: Rethink using fixed pt).
|
| - width = SkIntToFixed(width);
|
| - height = SkIntToFixed(height);
|
| -
|
| GrTexture* texture = glyph->fPlot->texture();
|
| SkASSERT(texture);
|
|
|
| @@ -231,18 +235,33 @@ HAS_ATLAS:
|
| SkASSERT(2*sizeof(GrPoint) == fDrawTarget->getDrawState().getVertexSize());
|
| }
|
|
|
| + SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft);
|
| + SkScalar dy = SkIntToScalar(glyph->fBounds.fTop);
|
| + SkScalar width = SkIntToScalar(glyph->fBounds.width());
|
| + SkScalar height = SkIntToScalar(glyph->fBounds.height());
|
| +
|
| + SkScalar scale = fTextSize/32.f;
|
| + dx *= scale;
|
| + dy *= scale;
|
| + sx += dx;
|
| + sy += dy;
|
| + width *= scale;
|
| + height *= scale;
|
| +
|
| GrFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX);
|
| GrFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY);
|
| + GrFixed tw = SkIntToFixed(glyph->fBounds.width());
|
| + GrFixed th = SkIntToFixed(glyph->fBounds.height());
|
|
|
| - fVertices[2*fCurrVertex].setRectFan(SkFixedToFloat(vx),
|
| - SkFixedToFloat(vy),
|
| - SkFixedToFloat(vx + width),
|
| - SkFixedToFloat(vy + height),
|
| + fVertices[2*fCurrVertex].setRectFan(sx,
|
| + sy,
|
| + sx + width,
|
| + sy + height,
|
| 2 * sizeof(SkPoint));
|
| - fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)),
|
| - SkFixedToFloat(texture->normalizeFixedY(ty)),
|
| - SkFixedToFloat(texture->normalizeFixedX(tx + width)),
|
| - SkFixedToFloat(texture->normalizeFixedY(ty + height)),
|
| + fVertices[2*fCurrVertex+1].setRectFan(SkFixedToScalar(texture->normalizeFixedX(tx)),
|
| + SkFixedToScalar(texture->normalizeFixedY(ty)),
|
| + SkFixedToScalar(texture->normalizeFixedX(tx + tw)),
|
| + SkFixedToScalar(texture->normalizeFixedY(ty + th)),
|
| 2 * sizeof(SkPoint));
|
| fCurrVertex += 4;
|
| }
|
|
|