OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 | 8 |
9 | 9 |
10 #include "GrTextContext.h" | 10 #include "GrTextContext.h" |
11 #include "GrAtlas.h" | 11 #include "GrAtlas.h" |
12 #include "GrContext.h" | 12 #include "GrContext.h" |
13 #include "GrDrawTarget.h" | 13 #include "GrDrawTarget.h" |
14 #include "GrFontScaler.h" | 14 #include "GrFontScaler.h" |
15 #include "GrIndexBuffer.h" | 15 #include "GrIndexBuffer.h" |
16 #include "GrTextStrike.h" | 16 #include "GrTextStrike.h" |
17 #include "GrTextStrike_impl.h" | 17 #include "GrTextStrike_impl.h" |
18 #include "SkPath.h" | 18 #include "SkPath.h" |
19 #include "SkStrokeRec.h" | 19 #include "SkStrokeRec.h" |
20 | 20 |
21 // glyph rendering shares this stage with edge rendering (kEdgeEffectStage in Gr
Context) && SW path | |
22 // rendering (kPathMaskStage in GrSWMaskHelper) | |
23 static const int kGlyphMaskStage = GrPaint::kTotalStages; | |
24 static const int kGlyphCoordsAttributeIndex = 1; | 21 static const int kGlyphCoordsAttributeIndex = 1; |
25 | 22 |
26 void GrTextContext::flushGlyphs() { | 23 void GrTextContext::flushGlyphs() { |
27 if (NULL == fDrawTarget) { | 24 if (NULL == fDrawTarget) { |
28 return; | 25 return; |
29 } | 26 } |
30 GrDrawTarget::AutoStateRestore asr(fDrawTarget, GrDrawTarget::kPreserve_ASRI
nit); | 27 |
31 GrDrawState* drawState = fDrawTarget->drawState(); | 28 GrDrawState* drawState = fDrawTarget->drawState(); |
| 29 GrDrawState::AutoRestoreEffects are(drawState); |
32 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); | 30 drawState->setFromPaint(fPaint, SkMatrix::I(), fContext->getRenderTarget()); |
33 | 31 |
34 if (fCurrVertex > 0) { | 32 if (fCurrVertex > 0) { |
35 // setup our sampler state for our text texture/atlas | 33 // setup our sampler state for our text texture/atlas |
36 GrAssert(GrIsALIGN4(fCurrVertex)); | 34 GrAssert(GrIsALIGN4(fCurrVertex)); |
37 GrAssert(fCurrTexture); | 35 GrAssert(fCurrTexture); |
38 GrTextureParams params(SkShader::kRepeat_TileMode, false); | 36 GrTextureParams params(SkShader::kRepeat_TileMode, false); |
39 | 37 |
40 // This effect could be stored with one of the cache objects (atlas?) | 38 // This effect could be stored with one of the cache objects (atlas?) |
41 drawState->setEffect(kGlyphMaskStage, | 39 drawState->addCoverageEffect( |
42 GrSimpleTextureEffect::CreateWithCustomCoords(fCurr
Texture, params), | 40 GrSimpleTextureEffect::CreateWithCustomCoords(fC
urrTexture, params), |
43 kGlyphCoordsAttributeIndex)->unref(); | 41 kGlyphCoordsAttributeIndex)->unref(); |
44 | 42 |
45 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { | 43 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { |
46 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || | 44 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || |
47 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || | 45 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || |
48 fPaint.hasColorStage()) { | 46 fPaint.hasColorStage()) { |
49 GrPrintf("LCD Text will not draw correctly.\n"); | 47 GrPrintf("LCD Text will not draw correctly.\n"); |
50 } | 48 } |
51 // setup blend so that we get mask * paintColor + (1-mask)*dstColor | 49 // setup blend so that we get mask * paintColor + (1-mask)*dstColor |
52 drawState->setBlendConstant(fPaint.getColor()); | 50 drawState->setBlendConstant(fPaint.getColor()); |
53 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); | 51 drawState->setBlendFunc(kConstC_GrBlendCoeff, kISC_GrBlendCoeff); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 SkFixedToFloat(vx + width), | 238 SkFixedToFloat(vx + width), |
241 SkFixedToFloat(vy + height), | 239 SkFixedToFloat(vy + height), |
242 2 * sizeof(SkPoint)); | 240 2 * sizeof(SkPoint)); |
243 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), | 241 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), |
244 SkFixedToFloat(texture->normalizeFixed
Y(ty)), | 242 SkFixedToFloat(texture->normalizeFixed
Y(ty)), |
245 SkFixedToFloat(texture->normalizeFixed
X(tx + width)), | 243 SkFixedToFloat(texture->normalizeFixed
X(tx + width)), |
246 SkFixedToFloat(texture->normalizeFixed
Y(ty + height)), | 244 SkFixedToFloat(texture->normalizeFixed
Y(ty + height)), |
247 2 * sizeof(SkPoint)); | 245 2 * sizeof(SkPoint)); |
248 fCurrVertex += 4; | 246 fCurrVertex += 4; |
249 } | 247 } |
OLD | NEW |