| 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 "GrFontScaler.h" | 11 #include "GrFontScaler.h" |
| 12 #include "SkGlyphCache.h" | 12 #include "SkGlyphCache.h" |
| 13 #include "GrIndexBuffer.h" | 13 #include "GrIndexBuffer.h" |
| 14 #include "GrTextStrike.h" | 14 #include "GrTextStrike.h" |
| 15 #include "GrTextStrike_impl.h" | 15 #include "GrTextStrike_impl.h" |
| 16 #include "SkGpuDevice.h" |
| 16 #include "SkPath.h" | 17 #include "SkPath.h" |
| 17 #include "SkRTConf.h" | 18 #include "SkRTConf.h" |
| 18 #include "SkStrokeRec.h" | 19 #include "SkStrokeRec.h" |
| 19 #include "effects/GrDistanceFieldTextureEffect.h" | 20 #include "effects/GrDistanceFieldTextureEffect.h" |
| 20 | 21 |
| 21 static const int kGlyphCoordsAttributeIndex = 1; | 22 static const int kGlyphCoordsAttributeIndex = 1; |
| 22 | 23 |
| 23 static const int kBaseDFFontSize = 32; | 24 static const int kBaseDFFontSize = 32; |
| 24 | 25 |
| 25 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, | 26 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, |
| 26 "Dump the contents of the font cache before every purge."); | 27 "Dump the contents of the font cache before every purge."); |
| 27 | 28 |
| 28 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, | 29 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, |
| 29 const GrPaint& grPaint, | 30 const GrPaint& grPaint, |
| 30 const SkPaint& skPaint) | 31 const SkPaint& skPaint, |
| 31 : GrTextContext(context, gr
Paint, skPaint) { | 32 const SkDeviceProperties&
properties) |
| 33 : GrTextContext(context, grPaint, sk
Paint, properties) { |
| 32 fStrike = NULL; | 34 fStrike = NULL; |
| 33 | 35 |
| 34 fCurrTexture = NULL; | 36 fCurrTexture = NULL; |
| 35 fCurrVertex = 0; | 37 fCurrVertex = 0; |
| 36 | 38 |
| 37 fVertices = NULL; | 39 fVertices = NULL; |
| 38 fMaxVertices = 0; | 40 fMaxVertices = 0; |
| 39 | 41 |
| 40 fTextRatio = fSkPaint.getTextSize()/kBaseDFFontSize; | 42 fTextRatio = fSkPaint.getTextSize()/kBaseDFFontSize; |
| 41 | 43 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 2 * sizeof(SkPoint)); | 278 2 * sizeof(SkPoint)); |
| 277 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), | 279 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), |
| 278 SkFixedToFloat(texture->normalizeFixed
Y(ty)), | 280 SkFixedToFloat(texture->normalizeFixed
Y(ty)), |
| 279 SkFixedToFloat(texture->normalizeFixed
X(tx + tw)), | 281 SkFixedToFloat(texture->normalizeFixed
X(tx + tw)), |
| 280 SkFixedToFloat(texture->normalizeFixed
Y(ty + th)), | 282 SkFixedToFloat(texture->normalizeFixed
Y(ty + th)), |
| 281 2 * sizeof(SkPoint)); | 283 2 * sizeof(SkPoint)); |
| 282 fCurrVertex += 4; | 284 fCurrVertex += 4; |
| 283 } | 285 } |
| 284 | 286 |
| 285 void GrDistanceFieldTextContext::drawText(const char text[], size_t byteLength, | 287 void GrDistanceFieldTextContext::drawText(const char text[], size_t byteLength, |
| 286 SkScalar x, SkScalar y, SkGlyphCache*
cache, | 288 SkScalar x, SkScalar y) { |
| 287 GrFontScaler* fontScaler) { | |
| 288 SkASSERT(byteLength == 0 || text != NULL); | 289 SkASSERT(byteLength == 0 || text != NULL); |
| 289 | 290 |
| 290 // nothing to draw | 291 // nothing to draw or can't draw |
| 291 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/)
{ | 292 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/ |
| 293 || fSkPaint.getRasterizer()) { |
| 292 return; | 294 return; |
| 293 } | 295 } |
| 294 | 296 |
| 295 SkScalar sizeRatio = fTextRatio; | 297 SkScalar sizeRatio = fTextRatio; |
| 296 | 298 |
| 297 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 299 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 298 | 300 |
| 301 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL); |
| 302 SkGlyphCache* cache = autoCache.getCache(); |
| 303 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 304 |
| 299 // need to measure first | 305 // need to measure first |
| 300 // TODO - generate positions and pre-load cache as well? | 306 // TODO - generate positions and pre-load cache as well? |
| 301 const char* stop = text + byteLength; | 307 const char* stop = text + byteLength; |
| 302 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { | 308 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { |
| 303 SkFixed stopX = 0; | 309 SkFixed stopX = 0; |
| 304 SkFixed stopY = 0; | 310 SkFixed stopY = 0; |
| 305 | 311 |
| 306 const char* textPtr = text; | 312 const char* textPtr = text; |
| 307 while (textPtr < stop) { | 313 while (textPtr < stop) { |
| 308 // don't need x, y here, since all subpixel variants will have the | 314 // don't need x, y here, since all subpixel variants will have the |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 fontScaler); | 347 fontScaler); |
| 342 } | 348 } |
| 343 | 349 |
| 344 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale); | 350 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale); |
| 345 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale); | 351 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale); |
| 346 } | 352 } |
| 347 } | 353 } |
| 348 | 354 |
| 349 void GrDistanceFieldTextContext::drawPosText(const char text[], size_t byteLengt
h, | 355 void GrDistanceFieldTextContext::drawPosText(const char text[], size_t byteLengt
h, |
| 350 const SkScalar pos[], SkScalar cons
tY, | 356 const SkScalar pos[], SkScalar cons
tY, |
| 351 int scalarsPerPosition, | 357 int scalarsPerPosition) { |
| 352 SkGlyphCache* cache, GrFontScaler*
fontScaler) { | |
| 353 | 358 |
| 354 SkASSERT(byteLength == 0 || text != NULL); | 359 SkASSERT(byteLength == 0 || text != NULL); |
| 355 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 360 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 356 | 361 |
| 357 // nothing to draw | 362 // nothing to draw |
| 358 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/)
{ | 363 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/ |
| 364 || fSkPaint.getRasterizer()) { |
| 359 return; | 365 return; |
| 360 } | 366 } |
| 361 | 367 |
| 362 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 368 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 363 | 369 |
| 370 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, NULL); |
| 371 SkGlyphCache* cache = autoCache.getCache(); |
| 372 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 373 |
| 364 const char* stop = text + byteLength; | 374 const char* stop = text + byteLength; |
| 365 | 375 |
| 366 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { | 376 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { |
| 367 while (text < stop) { | 377 while (text < stop) { |
| 368 // the last 2 parameters are ignored | 378 // the last 2 parameters are ignored |
| 369 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 379 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 370 | 380 |
| 371 if (glyph.fWidth) { | 381 if (glyph.fWidth) { |
| 372 SkScalar x = pos[0]; | 382 SkScalar x = pos[0]; |
| 373 SkScalar y = scalarsPerPosition == 1 ? constY : pos[1]; | 383 SkScalar y = scalarsPerPosition == 1 ? constY : pos[1]; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 397 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift) | 407 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift) |
| 398 + SK_FixedHalf, //d1g.fHalfSampleX, | 408 + SK_FixedHalf, //d1g.fHalfSampleX, |
| 399 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift) | 409 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift) |
| 400 + SK_FixedHalf, //d1g.fHalfSampleY, | 410 + SK_FixedHalf, //d1g.fHalfSampleY, |
| 401 fontScaler); | 411 fontScaler); |
| 402 } | 412 } |
| 403 pos += scalarsPerPosition; | 413 pos += scalarsPerPosition; |
| 404 } | 414 } |
| 405 } | 415 } |
| 406 } | 416 } |
| OLD | NEW |