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

Unified Diff: src/gpu/GrBitmapTextContext.cpp

Issue 45363002: Fix for issue 1728: raster vs. gpu text draws with the wrong color (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix alpha calculation Created 7 years, 2 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 | « include/gpu/GrBitmapTextContext.h ('k') | src/gpu/SkGpuDevice.cpp » ('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 7a99f093e5149108163a402a2aa9ee7788dc1f47..737e24baa1fcce416f2c5b902a5e521dba5dfec4 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,
+ SkColor color) :
GrTextContext(context, paint) {
fAutoMatrix.setIdentity(fContext, &fPaint);
+ fSkPaintColor = color;
+
fStrike = NULL;
fCurrTexture = NULL;
@@ -39,6 +43,13 @@ GrBitmapTextContext::~GrBitmapTextContext() {
this->flushGlyphs();
}
+static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
+ unsigned r = SkColorGetR(c);
+ unsigned g = SkColorGetG(c);
+ unsigned b = SkColorGetB(c);
+ return GrColorPackRGBA(r, g, b, 0xff);
+}
+
void GrBitmapTextContext::flushGlyphs() {
if (NULL == fDrawTarget) {
return;
@@ -65,12 +76,16 @@ void GrBitmapTextContext::flushGlyphs() {
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 = SkColorGetA(fSkPaintColor);
+ // paintAlpha
+ drawState->setColor(SkColorSetARGB(a, a, a, a));
+ // paintColor
+ drawState->setBlendConstant(skcolor_to_grcolor_nopremultiply(fSkPaintColor));
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);
} else {
// set back to normal in case we took LCD path previously.
drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff());
@@ -82,6 +97,7 @@ void GrBitmapTextContext::flushGlyphs() {
fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
nGlyphs,
4, 6);
+
fDrawTarget->resetVertexSource();
fVertices = NULL;
fMaxVertices = 0;
« no previous file with comments | « include/gpu/GrBitmapTextContext.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698