OLD | NEW |
---|---|
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 GrColor color) : | |
26 GrTextContext(context, paint) { | 28 GrTextContext(context, paint) { |
27 fAutoMatrix.setIdentity(fContext, &fPaint); | 29 fAutoMatrix.setIdentity(fContext, &fPaint); |
28 | 30 |
31 fPaintColorNoPreMultAlpha = 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() { |
(...skipping 13 matching lines...) Expand all Loading... | |
52 // setup our sampler state for our text texture/atlas | 56 // setup our sampler state for our text texture/atlas |
53 SkASSERT(GrIsALIGN4(fCurrVertex)); | 57 SkASSERT(GrIsALIGN4(fCurrVertex)); |
54 SkASSERT(fCurrTexture); | 58 SkASSERT(fCurrTexture); |
55 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon e_FilterMode); | 59 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNon e_FilterMode); |
56 | 60 |
57 // This effect could be stored with one of the cache objects (atlas?) | 61 // This effect could be stored with one of the cache objects (atlas?) |
58 drawState->addCoverageEffect( | 62 drawState->addCoverageEffect( |
59 GrCustomCoordsTextureEffect::Create(fCurrTexture , params), | 63 GrCustomCoordsTextureEffect::Create(fCurrTexture , params), |
60 kGlyphCoordsAttributeIndex)->unref(); | 64 kGlyphCoordsAttributeIndex)->unref(); |
61 | 65 |
66 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.
| |
62 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { | 67 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { |
63 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || | 68 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || |
64 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || | 69 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || |
65 fPaint.numColorStages()) { | 70 fPaint.numColorStages()) { |
66 GrPrintf("LCD Text will not draw correctly.\n"); | 71 GrPrintf("LCD Text will not draw correctly.\n"); |
67 } | 72 } |
68 // setup blend so that we get mask * paintColor + (1-mask)*dstColor | 73 // We don't use the GrPaint's color in this case because it's been p remultiplied by |
69 drawState->setBlendConstant(fPaint.getColor()); | 74 // alpha. Instead we feed in a non-premultiplied color, and multiply its alpha by |
75 // the mask texture color. The end result is that we get | |
76 // mask*paintAlpha*paintColor + (1-mask*paintAlpha)*dstCo lor | |
77 int a = SkGetPackedA32(fPaintColorNoPreMultAlpha); | |
78 drawState->setBlendConstant(fPaintColorNoPreMultAlpha); | |
70 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); | 79 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); |
71 // don't modulate by the paint's color in the frag since we're | 80 drawState->setColor(SkColorSetARGB(a, a, a, a)); |
72 // already doing it via the blend const. | |
73 drawState->setColor(0xffffffff); | |
74 } else { | 81 } else { |
75 // set back to normal in case we took LCD path previously. | 82 // set back to normal in case we took LCD path previously. |
76 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff()); | 83 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff()); |
77 drawState->setColor(fPaint.getColor()); | 84 drawState->setColor(fPaint.getColor()); |
78 } | 85 } |
79 | 86 |
80 int nGlyphs = fCurrVertex / 4; | 87 int nGlyphs = fCurrVertex / 4; |
81 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); | 88 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); |
82 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, | 89 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, |
83 nGlyphs, | 90 nGlyphs, |
84 4, 6); | 91 4, 6); |
92 | |
93 if (lcdAlpha) { | |
94 // in second pass add mask*paintColor to dst | |
95 drawState->setBlendFunc(kOne_GrBlendCoeff, kOne_GrBlendCoeff); | |
96 drawState->setColor(fPaint.getColor()); | |
97 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, | |
98 nGlyphs, | |
99 4, 6); | |
100 } | |
101 | |
85 fDrawTarget->resetVertexSource(); | 102 fDrawTarget->resetVertexSource(); |
86 fVertices = NULL; | 103 fVertices = NULL; |
87 fMaxVertices = 0; | 104 fMaxVertices = 0; |
88 fCurrVertex = 0; | 105 fCurrVertex = 0; |
89 SkSafeSetNull(fCurrTexture); | 106 SkSafeSetNull(fCurrTexture); |
90 } | 107 } |
91 } | 108 } |
92 | 109 |
93 namespace { | 110 namespace { |
94 | 111 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 SkFixedToFloat(vx + width), | 256 SkFixedToFloat(vx + width), |
240 SkFixedToFloat(vy + height), | 257 SkFixedToFloat(vy + height), |
241 2 * sizeof(SkPoint)); | 258 2 * sizeof(SkPoint)); |
242 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed X(tx)), | 259 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed X(tx)), |
243 SkFixedToFloat(texture->normalizeFixed Y(ty)), | 260 SkFixedToFloat(texture->normalizeFixed Y(ty)), |
244 SkFixedToFloat(texture->normalizeFixed X(tx + width)), | 261 SkFixedToFloat(texture->normalizeFixed X(tx + width)), |
245 SkFixedToFloat(texture->normalizeFixed Y(ty + height)), | 262 SkFixedToFloat(texture->normalizeFixed Y(ty + height)), |
246 2 * sizeof(SkPoint)); | 263 2 * sizeof(SkPoint)); |
247 fCurrVertex += 4; | 264 fCurrVertex += 4; |
248 } | 265 } |
OLD | NEW |