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

Side by Side 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, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/gpu/GrBitmapTextContext.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrBitmapTextContext.h" 8 #include "GrBitmapTextContext.h"
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrDrawTarget.h" 10 #include "GrDrawTarget.h"
11 #include "GrFontScaler.h" 11 #include "GrFontScaler.h"
12 #include "GrIndexBuffer.h" 12 #include "GrIndexBuffer.h"
13 #include "GrTextStrike.h" 13 #include "GrTextStrike.h"
14 #include "GrTextStrike_impl.h" 14 #include "GrTextStrike_impl.h"
15 #include "SkColorPriv.h"
15 #include "SkPath.h" 16 #include "SkPath.h"
16 #include "SkRTConf.h" 17 #include "SkRTConf.h"
17 #include "SkStrokeRec.h" 18 #include "SkStrokeRec.h"
18 #include "effects/GrCustomCoordsTextureEffect.h" 19 #include "effects/GrCustomCoordsTextureEffect.h"
19 20
20 static const int kGlyphCoordsAttributeIndex = 1; 21 static const int kGlyphCoordsAttributeIndex = 1;
21 22
22 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, 23 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
23 "Dump the contents of the font cache before every purge."); 24 "Dump the contents of the font cache before every purge.");
24 25
25 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, const GrPaint& pain t) : 26 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, const GrPaint& pain t,
27 SkColor color) :
26 GrTextContext(context, paint) { 28 GrTextContext(context, paint) {
27 fAutoMatrix.setIdentity(fContext, &fPaint); 29 fAutoMatrix.setIdentity(fContext, &fPaint);
28 30
31 fSkPaintColor = color;
32
29 fStrike = NULL; 33 fStrike = NULL;
30 34
31 fCurrTexture = NULL; 35 fCurrTexture = NULL;
32 fCurrVertex = 0; 36 fCurrVertex = 0;
33 37
34 fVertices = NULL; 38 fVertices = NULL;
35 fMaxVertices = 0; 39 fMaxVertices = 0;
36 } 40 }
37 41
38 GrBitmapTextContext::~GrBitmapTextContext() { 42 GrBitmapTextContext::~GrBitmapTextContext() {
39 this->flushGlyphs(); 43 this->flushGlyphs();
40 } 44 }
41 45
46 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) {
47 unsigned r = SkColorGetR(c);
48 unsigned g = SkColorGetG(c);
49 unsigned b = SkColorGetB(c);
50 return GrColorPackRGBA(r, g, b, 0xff);
51 }
52
42 void GrBitmapTextContext::flushGlyphs() { 53 void GrBitmapTextContext::flushGlyphs() {
43 if (NULL == fDrawTarget) { 54 if (NULL == fDrawTarget) {
44 return; 55 return;
45 } 56 }
46 57
47 GrDrawState* drawState = fDrawTarget->drawState(); 58 GrDrawState* drawState = fDrawTarget->drawState();
48 GrDrawState::AutoRestoreEffects are(drawState); 59 GrDrawState::AutoRestoreEffects are(drawState);
49 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); 60 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget());
50 61
51 if (fCurrVertex > 0) { 62 if (fCurrVertex > 0) {
52 // setup our sampler state for our text texture/atlas 63 // setup our sampler state for our text texture/atlas
53 SkASSERT(GrIsALIGN4(fCurrVertex)); 64 SkASSERT(GrIsALIGN4(fCurrVertex));
54 SkASSERT(fCurrTexture); 65 SkASSERT(fCurrTexture);
55 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon e_FilterMode); 66 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon e_FilterMode);
56 67
57 // This effect could be stored with one of the cache objects (atlas?) 68 // This effect could be stored with one of the cache objects (atlas?)
58 drawState->addCoverageEffect( 69 drawState->addCoverageEffect(
59 GrCustomCoordsTextureEffect::Create(fCurrTexture , params), 70 GrCustomCoordsTextureEffect::Create(fCurrTexture , params),
60 kGlyphCoordsAttributeIndex)->unref(); 71 kGlyphCoordsAttributeIndex)->unref();
61 72
62 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { 73 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
63 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || 74 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() ||
64 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || 75 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() ||
65 fPaint.numColorStages()) { 76 fPaint.numColorStages()) {
66 GrPrintf("LCD Text will not draw correctly.\n"); 77 GrPrintf("LCD Text will not draw correctly.\n");
67 } 78 }
68 // setup blend so that we get mask * paintColor + (1-mask)*dstColor 79 // We don't use the GrPaint's color in this case because it's been p remultiplied by
69 drawState->setBlendConstant(fPaint.getColor()); 80 // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by
81 // the mask texture color. The end result is that we get
82 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo lor
83 int a = SkColorGetA(fSkPaintColor);
84 // paintAlpha
85 drawState->setColor(SkColorSetARGB(a, a, a, a));
86 // paintColor
87 drawState->setBlendConstant(skcolor_to_grcolor_nopremultiply(fSkPain tColor));
70 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); 88 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff);
71 // don't modulate by the paint's color in the frag since we're
72 // already doing it via the blend const.
73 drawState->setColor(0xffffffff);
74 } else { 89 } else {
75 // set back to normal in case we took LCD path previously. 90 // set back to normal in case we took LCD path previously.
76 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff()); 91 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff());
77 drawState->setColor(fPaint.getColor()); 92 drawState->setColor(fPaint.getColor());
78 } 93 }
79 94
80 int nGlyphs = fCurrVertex / 4; 95 int nGlyphs = fCurrVertex / 4;
81 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); 96 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
82 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, 97 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
83 nGlyphs, 98 nGlyphs,
84 4, 6); 99 4, 6);
100
85 fDrawTarget->resetVertexSource(); 101 fDrawTarget->resetVertexSource();
86 fVertices = NULL; 102 fVertices = NULL;
87 fMaxVertices = 0; 103 fMaxVertices = 0;
88 fCurrVertex = 0; 104 fCurrVertex = 0;
89 SkSafeSetNull(fCurrTexture); 105 SkSafeSetNull(fCurrTexture);
90 } 106 }
91 } 107 }
92 108
93 namespace { 109 namespace {
94 110
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 SkFixedToFloat(vx + width), 255 SkFixedToFloat(vx + width),
240 SkFixedToFloat(vy + height), 256 SkFixedToFloat(vy + height),
241 2 * sizeof(SkPoint)); 257 2 * sizeof(SkPoint));
242 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed X(tx)), 258 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed X(tx)),
243 SkFixedToFloat(texture->normalizeFixed Y(ty)), 259 SkFixedToFloat(texture->normalizeFixed Y(ty)),
244 SkFixedToFloat(texture->normalizeFixed X(tx + width)), 260 SkFixedToFloat(texture->normalizeFixed X(tx + width)),
245 SkFixedToFloat(texture->normalizeFixed Y(ty + height)), 261 SkFixedToFloat(texture->normalizeFixed Y(ty + height)),
246 2 * sizeof(SkPoint)); 262 2 * sizeof(SkPoint));
247 fCurrVertex += 4; 263 fCurrVertex += 4;
248 } 264 }
OLDNEW
« 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