| 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 "GrBitmapTextContext.h" | 10 #include "GrBitmapTextContext.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "SkColorFilter.h" | 21 #include "SkColorFilter.h" |
| 22 #include "SkDistanceFieldGen.h" | 22 #include "SkDistanceFieldGen.h" |
| 23 #include "SkDraw.h" | 23 #include "SkDraw.h" |
| 24 #include "SkGlyphCache.h" | 24 #include "SkGlyphCache.h" |
| 25 #include "SkGpuDevice.h" | 25 #include "SkGpuDevice.h" |
| 26 #include "SkPath.h" | 26 #include "SkPath.h" |
| 27 #include "SkRTConf.h" | 27 #include "SkRTConf.h" |
| 28 #include "SkStrokeRec.h" | 28 #include "SkStrokeRec.h" |
| 29 #include "effects/GrDistanceFieldTextureEffect.h" | 29 #include "effects/GrDistanceFieldTextureEffect.h" |
| 30 | 30 |
| 31 #include "SkDrawProcs.h" |
| 32 #include "SkTextMapStateProc.h" |
| 33 |
| 31 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, | 34 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, |
| 32 "Dump the contents of the font cache before every purge."); | 35 "Dump the contents of the font cache before every purge."); |
| 33 | 36 |
| 34 static const int kSmallDFFontSize = 32; | 37 static const int kSmallDFFontSize = 32; |
| 35 static const int kSmallDFFontLimit = 32; | 38 static const int kSmallDFFontLimit = 32; |
| 36 static const int kMediumDFFontSize = 64; | 39 static const int kMediumDFFontSize = 64; |
| 37 static const int kMediumDFFontLimit = 64; | 40 static const int kMediumDFFontLimit = 64; |
| 38 static const int kLargeDFFontSize = 128; | 41 static const int kLargeDFFontSize = 128; |
| 39 | 42 |
| 40 namespace { | 43 namespace { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 if (NULL == *gammaTexture) { | 203 if (NULL == *gammaTexture) { |
| 201 return; | 204 return; |
| 202 } | 205 } |
| 203 | 206 |
| 204 (*gammaTexture)->writePixels(0, 0, width, height, | 207 (*gammaTexture)->writePixels(0, 0, width, height, |
| 205 (*gammaTexture)->config(), data.get(), 0, | 208 (*gammaTexture)->config(), data.get(), 0, |
| 206 GrContext::kDontFlush_PixelOpsFlag); | 209 GrContext::kDontFlush_PixelOpsFlag); |
| 207 } | 210 } |
| 208 } | 211 } |
| 209 | 212 |
| 210 void GrDistanceFieldTextContext::onDrawText(const GrPaint& paint, const SkPaint&
skPaint, | |
| 211 const char text[], size_t byteLength, | |
| 212 SkScalar x, SkScalar y) { | |
| 213 SkASSERT(byteLength == 0 || text != NULL); | |
| 214 | |
| 215 // nothing to draw or can't draw | |
| 216 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/ | |
| 217 || fSkPaint.getRasterizer()) { | |
| 218 return; | |
| 219 } | |
| 220 | |
| 221 this->init(paint, skPaint); | |
| 222 | |
| 223 SkScalar sizeRatio = fTextRatio; | |
| 224 | |
| 225 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | |
| 226 | |
| 227 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); | |
| 228 SkGlyphCache* cache = autoCache.getCache(); | |
| 229 GrFontScaler* fontScaler = GetGrFontScaler(cache); | |
| 230 | |
| 231 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); | |
| 232 | |
| 233 // need to measure first | |
| 234 // TODO - generate positions and pre-load cache as well? | |
| 235 const char* stop = text + byteLength; | |
| 236 if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) { | |
| 237 SkFixed stopX = 0; | |
| 238 SkFixed stopY = 0; | |
| 239 | |
| 240 const char* textPtr = text; | |
| 241 while (textPtr < stop) { | |
| 242 // don't need x, y here, since all subpixel variants will have the | |
| 243 // same advance | |
| 244 const SkGlyph& glyph = glyphCacheProc(cache, &textPtr, 0, 0); | |
| 245 | |
| 246 stopX += glyph.fAdvanceX; | |
| 247 stopY += glyph.fAdvanceY; | |
| 248 } | |
| 249 SkASSERT(textPtr == stop); | |
| 250 | |
| 251 SkScalar alignX = SkFixedToScalar(stopX)*sizeRatio; | |
| 252 SkScalar alignY = SkFixedToScalar(stopY)*sizeRatio; | |
| 253 | |
| 254 if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) { | |
| 255 alignX = SkScalarHalf(alignX); | |
| 256 alignY = SkScalarHalf(alignY); | |
| 257 } | |
| 258 | |
| 259 x -= alignX; | |
| 260 y -= alignY; | |
| 261 } | |
| 262 | |
| 263 SkFixed fx = SkScalarToFixed(x); | |
| 264 SkFixed fy = SkScalarToFixed(y); | |
| 265 SkFixed fixedScale = SkScalarToFixed(sizeRatio); | |
| 266 while (text < stop) { | |
| 267 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | |
| 268 | |
| 269 if (glyph.fWidth) { | |
| 270 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), | |
| 271 glyph.getSubXFixed(), | |
| 272 glyph.getSubYFixed()), | |
| 273 fx, | |
| 274 fy, | |
| 275 fontScaler); | |
| 276 } | |
| 277 | |
| 278 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale); | |
| 279 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale); | |
| 280 } | |
| 281 | |
| 282 this->finish(); | |
| 283 } | |
| 284 | |
| 285 void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPai
nt& skPaint, | 213 void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPai
nt& skPaint, |
| 286 const char text[], size_t byteLengt
h, | 214 const char text[], size_t byteLengt
h, |
| 287 const SkScalar pos[], int scalarsPe
rPosition, | 215 const SkScalar pos[], int scalarsPe
rPosition, |
| 288 const SkPoint& offset) { | 216 const SkPoint& offset) { |
| 289 | 217 |
| 290 SkASSERT(byteLength == 0 || text != NULL); | 218 SkASSERT(byteLength == 0 || text != NULL); |
| 291 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 219 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 292 | 220 |
| 293 // nothing to draw | 221 // nothing to draw |
| 294 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/)
{ | 222 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/)
{ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 319 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), | 247 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 320 glyph.getSubXFixed(), | 248 glyph.getSubXFixed(), |
| 321 glyph.getSubYFixed()), | 249 glyph.getSubYFixed()), |
| 322 SkScalarToFixed(x), | 250 SkScalarToFixed(x), |
| 323 SkScalarToFixed(y), | 251 SkScalarToFixed(y), |
| 324 fontScaler); | 252 fontScaler); |
| 325 } | 253 } |
| 326 pos += scalarsPerPosition; | 254 pos += scalarsPerPosition; |
| 327 } | 255 } |
| 328 } else { | 256 } else { |
| 329 int alignShift = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ? 1 :
0; | 257 SkScalar alignMul = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ?
SK_ScalarHalf |
| 258 :
SK_Scalar1; |
| 330 while (text < stop) { | 259 while (text < stop) { |
| 331 // the last 2 parameters are ignored | 260 // the last 2 parameters are ignored |
| 332 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 261 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 333 | 262 |
| 334 if (glyph.fWidth) { | 263 if (glyph.fWidth) { |
| 335 SkScalar x = offset.x() + pos[0]; | 264 SkScalar x = offset.x() + pos[0]; |
| 336 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; | 265 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; |
| 337 | 266 |
| 267 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX)*alignMul*fT
extRatio; |
| 268 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY)*alignMul*fT
extRatio; |
| 269 |
| 338 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), | 270 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 339 glyph.getSubXFixed(), | 271 glyph.getSubXFixed(), |
| 340 glyph.getSubYFixed()), | 272 glyph.getSubYFixed()), |
| 341 SkScalarToFixed(x) - (glyph.fAdvanceX >> align
Shift), | 273 SkScalarToFixed(x - advanceX), |
| 342 SkScalarToFixed(y) - (glyph.fAdvanceY >> align
Shift), | 274 SkScalarToFixed(y - advanceY), |
| 343 fontScaler); | 275 fontScaler); |
| 344 } | 276 } |
| 345 pos += scalarsPerPosition; | 277 pos += scalarsPerPosition; |
| 346 } | 278 } |
| 347 } | 279 } |
| 348 | 280 |
| 349 this->finish(); | 281 this->finish(); |
| 350 } | 282 } |
| 351 | 283 |
| 352 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { | 284 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 fVertexBounds.setLargestInverted(); | 613 fVertexBounds.setLargestInverted(); |
| 682 } | 614 } |
| 683 } | 615 } |
| 684 | 616 |
| 685 inline void GrDistanceFieldTextContext::finish() { | 617 inline void GrDistanceFieldTextContext::finish() { |
| 686 this->flush(); | 618 this->flush(); |
| 687 | 619 |
| 688 GrTextContext::finish(); | 620 GrTextContext::finish(); |
| 689 } | 621 } |
| 690 | 622 |
| OLD | NEW |