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 "GrDistanceFieldTextContext.h" | 8 #include "GrDistanceFieldTextContext.h" |
9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
| 11 #include "GrDrawTargetCaps.h" |
11 #include "GrFontScaler.h" | 12 #include "GrFontScaler.h" |
12 #include "SkGlyphCache.h" | 13 #include "SkGlyphCache.h" |
13 #include "GrIndexBuffer.h" | 14 #include "GrIndexBuffer.h" |
14 #include "GrTextStrike.h" | 15 #include "GrTextStrike.h" |
15 #include "GrTextStrike_impl.h" | 16 #include "GrTextStrike_impl.h" |
16 #include "SkDraw.h" | 17 #include "SkDraw.h" |
17 #include "SkGpuDevice.h" | 18 #include "SkGpuDevice.h" |
18 #include "SkPath.h" | 19 #include "SkPath.h" |
19 #include "SkRTConf.h" | 20 #include "SkRTConf.h" |
20 #include "SkStrokeRec.h" | 21 #include "SkStrokeRec.h" |
(...skipping 18 matching lines...) Expand all Loading... |
39 fMaxVertices = 0; | 40 fMaxVertices = 0; |
40 } | 41 } |
41 | 42 |
42 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { | 43 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { |
43 this->flushGlyphs(); | 44 this->flushGlyphs(); |
44 } | 45 } |
45 | 46 |
46 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { | 47 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { |
47 return !paint.getRasterizer() && !paint.getMaskFilter() && | 48 return !paint.getRasterizer() && !paint.getMaskFilter() && |
48 paint.getStyle() == SkPaint::kFill_Style && | 49 paint.getStyle() == SkPaint::kFill_Style && |
| 50 fContext->getTextTarget()->caps()->shaderDerivativeSupport() && |
49 !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix()); | 51 !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix()); |
50 } | 52 } |
51 | 53 |
52 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { | 54 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { |
53 unsigned r = SkColorGetR(c); | 55 unsigned r = SkColorGetR(c); |
54 unsigned g = SkColorGetG(c); | 56 unsigned g = SkColorGetG(c); |
55 unsigned b = SkColorGetB(c); | 57 unsigned b = SkColorGetB(c); |
56 return GrColorPackRGBA(r, g, b, 0xff); | 58 return GrColorPackRGBA(r, g, b, 0xff); |
57 } | 59 } |
58 | 60 |
59 void GrDistanceFieldTextContext::flushGlyphs() { | 61 void GrDistanceFieldTextContext::flushGlyphs() { |
60 if (NULL == fDrawTarget) { | 62 if (NULL == fDrawTarget) { |
61 return; | 63 return; |
62 } | 64 } |
63 | 65 |
64 GrDrawState* drawState = fDrawTarget->drawState(); | 66 GrDrawState* drawState = fDrawTarget->drawState(); |
65 GrDrawState::AutoRestoreEffects are(drawState); | 67 GrDrawState::AutoRestoreEffects are(drawState); |
66 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa
rget()); | 68 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa
rget()); |
67 | 69 |
68 if (fCurrVertex > 0) { | 70 if (fCurrVertex > 0) { |
69 // setup our sampler state for our text texture/atlas | 71 // setup our sampler state for our text texture/atlas |
70 SkASSERT(GrIsALIGN4(fCurrVertex)); | 72 SkASSERT(GrIsALIGN4(fCurrVertex)); |
71 SkASSERT(fCurrTexture); | 73 SkASSERT(fCurrTexture); |
72 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil
erp_FilterMode); | 74 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil
erp_FilterMode); |
73 | 75 |
74 // This effect could be stored with one of the cache objects (atlas?) | 76 // This effect could be stored with one of the cache objects (atlas?) |
| 77 SkISize size = fStrike->getAtlasSize(); |
75 drawState->addCoverageEffect( | 78 drawState->addCoverageEffect( |
76 GrDistanceFieldTextureEffect::Create(fCurrTextur
e, params), | 79 GrDistanceFieldTextureEffect::Create(fCurrTextur
e, params, size), |
77 kGlyphCoordsAttributeIndex)->unref(); | 80 kGlyphCoordsAttributeIndex)->unref(); |
78 | 81 |
79 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { | 82 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { |
80 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || | 83 if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() || |
81 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || | 84 kISA_GrBlendCoeff != fPaint.getDstBlendCoeff() || |
82 fPaint.numColorStages()) { | 85 fPaint.numColorStages()) { |
83 GrPrintf("LCD Text will not draw correctly.\n"); | 86 GrPrintf("LCD Text will not draw correctly.\n"); |
84 } | 87 } |
85 // We don't use the GrPaint's color in this case because it's been p
remultiplied by | 88 // We don't use the GrPaint's color in this case because it's been p
remultiplied by |
86 // alpha. Instead we feed in a non-premultiplied color, and multiply
its alpha by | 89 // alpha. Instead we feed in a non-premultiplied color, and multiply
its alpha by |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 SkScalar width = SkIntToScalar(glyph->fBounds.width()); | 259 SkScalar width = SkIntToScalar(glyph->fBounds.width()); |
257 SkScalar height = SkIntToScalar(glyph->fBounds.height()); | 260 SkScalar height = SkIntToScalar(glyph->fBounds.height()); |
258 | 261 |
259 SkScalar scale = fTextRatio; | 262 SkScalar scale = fTextRatio; |
260 dx *= scale; | 263 dx *= scale; |
261 dy *= scale; | 264 dy *= scale; |
262 sx += dx; | 265 sx += dx; |
263 sy += dy; | 266 sy += dy; |
264 width *= scale; | 267 width *= scale; |
265 height *= scale; | 268 height *= scale; |
266 | 269 |
267 GrFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); | 270 GrFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); |
268 GrFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); | 271 GrFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); |
269 GrFixed tw = SkIntToFixed(glyph->fBounds.width()); | 272 GrFixed tw = SkIntToFixed(glyph->fBounds.width()); |
270 GrFixed th = SkIntToFixed(glyph->fBounds.height()); | 273 GrFixed th = SkIntToFixed(glyph->fBounds.height()); |
271 | 274 |
| 275 static const size_t kVertexSize = 2 * sizeof(SkPoint); |
272 fVertices[2*fCurrVertex].setRectFan(sx, | 276 fVertices[2*fCurrVertex].setRectFan(sx, |
273 sy, | 277 sy, |
274 sx + width, | 278 sx + width, |
275 sy + height, | 279 sy + height, |
276 2 * sizeof(SkPoint)); | 280 kVertexSize); |
277 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), | 281 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), |
278 SkFixedToFloat(texture->normalizeFixed
Y(ty)), | 282 SkFixedToFloat(texture->normalizeFixed
Y(ty)), |
279 SkFixedToFloat(texture->normalizeFixed
X(tx + tw)), | 283 SkFixedToFloat(texture->normalizeFixed
X(tx + tw)), |
280 SkFixedToFloat(texture->normalizeFixed
Y(ty + th)), | 284 SkFixedToFloat(texture->normalizeFixed
Y(ty + th)), |
281 2 * sizeof(SkPoint)); | 285 kVertexSize); |
282 fCurrVertex += 4; | 286 fCurrVertex += 4; |
283 } | 287 } |
284 | 288 |
285 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint
& skPaint) { | 289 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint
& skPaint) { |
286 GrTextContext::init(paint, skPaint); | 290 GrTextContext::init(paint, skPaint); |
287 | 291 |
288 fStrike = NULL; | 292 fStrike = NULL; |
289 | 293 |
290 fCurrTexture = NULL; | 294 fCurrTexture = NULL; |
291 fCurrVertex = 0; | 295 fCurrVertex = 0; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift) | 443 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift) |
440 + SK_FixedHalf, //d1g.fHalfSampleY, | 444 + SK_FixedHalf, //d1g.fHalfSampleY, |
441 fontScaler); | 445 fontScaler); |
442 } | 446 } |
443 pos += scalarsPerPosition; | 447 pos += scalarsPerPosition; |
444 } | 448 } |
445 } | 449 } |
446 | 450 |
447 this->finish(); | 451 this->finish(); |
448 } | 452 } |
OLD | NEW |