Chromium Code Reviews| Index: src/gpu/GrBitmapTextContext.cpp |
| diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp |
| index 7a99f093e5149108163a402a2aa9ee7788dc1f47..aebc53794d81606683529eebc447b7163f46881c 100755 |
| --- a/src/gpu/GrBitmapTextContext.cpp |
| +++ b/src/gpu/GrBitmapTextContext.cpp |
| @@ -12,6 +12,7 @@ |
| #include "GrIndexBuffer.h" |
| #include "GrTextStrike.h" |
| #include "GrTextStrike_impl.h" |
| +#include "SkColorPriv.h" |
| #include "SkPath.h" |
| #include "SkRTConf.h" |
| #include "SkStrokeRec.h" |
| @@ -22,10 +23,13 @@ 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) : |
| +GrBitmapTextContext::GrBitmapTextContext(GrContext* context, const GrPaint& paint, |
| + GrColor color) : |
| GrTextContext(context, paint) { |
| fAutoMatrix.setIdentity(fContext, &fPaint); |
| + fPaintColorNoPreMultAlpha = color; |
| + |
| fStrike = NULL; |
| fCurrTexture = NULL; |
| @@ -59,18 +63,21 @@ void GrBitmapTextContext::flushGlyphs() { |
| GrCustomCoordsTextureEffect::Create(fCurrTexture, params), |
| kGlyphCoordsAttributeIndex)->unref(); |
| + bool lcdAlpha = false; |
|
bsalomon
2013/10/28 13:12:21
this and the below code guarded by this var don't
jvanverth1
2013/10/28 14:00:52
Done.
|
| if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { |
| if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || |
| kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || |
| fPaint.numColorStages()) { |
| GrPrintf("LCD Text will not draw correctly.\n"); |
| } |
| - // setup blend so that we get mask * paintColor + (1-mask)*dstColor |
| - drawState->setBlendConstant(fPaint.getColor()); |
| + // We don't use the GrPaint's color in this case because it's been premultiplied by |
| + // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by |
| + // the mask texture color. The end result is that we get |
| + // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstColor |
| + int a = SkGetPackedA32(fPaintColorNoPreMultAlpha); |
| + drawState->setBlendConstant(fPaintColorNoPreMultAlpha); |
| drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); |
| - // don't modulate by the paint's color in the frag since we're |
| - // already doing it via the blend const. |
| - drawState->setColor(0xffffffff); |
| + drawState->setColor(SkColorSetARGB(a, a, a, a)); |
| } else { |
| // set back to normal in case we took LCD path previously. |
| drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff()); |
| @@ -82,6 +89,16 @@ void GrBitmapTextContext::flushGlyphs() { |
| fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, |
| nGlyphs, |
| 4, 6); |
| + |
| + if (lcdAlpha) { |
| + // in second pass add mask*paintColor to dst |
| + drawState->setBlendFunc(kOne_GrBlendCoeff, kOne_GrBlendCoeff); |
| + drawState->setColor(fPaint.getColor()); |
| + fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, |
| + nGlyphs, |
| + 4, 6); |
| + } |
| + |
| fDrawTarget->resetVertexSource(); |
| fVertices = NULL; |
| fMaxVertices = 0; |