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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 105 } |
106 | 106 |
107 // TODO: add some stroking support | 107 // TODO: add some stroking support |
108 if (paint.getStyle() != SkPaint::kFill_Style) { | 108 if (paint.getStyle() != SkPaint::kFill_Style) { |
109 return false; | 109 return false; |
110 } | 110 } |
111 | 111 |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 inline void GrDistanceFieldTextContext::init(GrRenderTarget* rt, const GrPaint&
paint, | 115 inline void GrDistanceFieldTextContext::init(GrRenderTarget* rt, const GrClip& c
lip, |
116 const SkPaint& skPaint) { | 116 const GrPaint& paint, const SkPaint
& skPaint) { |
117 GrTextContext::init(rt, paint, skPaint); | 117 GrTextContext::init(rt, clip, paint, skPaint); |
118 | 118 |
119 fStrike = NULL; | 119 fStrike = NULL; |
120 | 120 |
121 const SkMatrix& ctm = fViewMatrix; | 121 const SkMatrix& ctm = fViewMatrix; |
122 | 122 |
123 // getMaxScale doesn't support perspective, so neither do we at the moment | 123 // getMaxScale doesn't support perspective, so neither do we at the moment |
124 SkASSERT(!ctm.hasPerspective()); | 124 SkASSERT(!ctm.hasPerspective()); |
125 SkScalar maxScale = ctm.getMaxScale(); | 125 SkScalar maxScale = ctm.getMaxScale(); |
126 SkScalar textSize = fSkPaint.getTextSize(); | 126 SkScalar textSize = fSkPaint.getTextSize(); |
127 SkScalar scaledTextSize = textSize; | 127 SkScalar scaledTextSize = textSize; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 if (NULL == *gammaTexture) { | 200 if (NULL == *gammaTexture) { |
201 return; | 201 return; |
202 } | 202 } |
203 | 203 |
204 (*gammaTexture)->writePixels(0, 0, width, height, | 204 (*gammaTexture)->writePixels(0, 0, width, height, |
205 (*gammaTexture)->config(), data.get(), 0, | 205 (*gammaTexture)->config(), data.get(), 0, |
206 GrContext::kDontFlush_PixelOpsFlag); | 206 GrContext::kDontFlush_PixelOpsFlag); |
207 } | 207 } |
208 } | 208 } |
209 | 209 |
210 void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrPaint& p
aint, | 210 void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrClip& cl
ip, |
| 211 const GrPaint& paint, |
211 const SkPaint& skPaint, const SkMatr
ix& viewMatrix, | 212 const SkPaint& skPaint, const SkMatr
ix& viewMatrix, |
212 const char text[], size_t byteLength
, | 213 const char text[], size_t byteLength
, |
213 SkScalar x, SkScalar y) { | 214 SkScalar x, SkScalar y) { |
214 SkASSERT(byteLength == 0 || text != NULL); | 215 SkASSERT(byteLength == 0 || text != NULL); |
215 | 216 |
216 // nothing to draw | 217 // nothing to draw |
217 if (text == NULL || byteLength == 0) { | 218 if (text == NULL || byteLength == 0) { |
218 return; | 219 return; |
219 } | 220 } |
220 | 221 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 alignX = SkScalarHalf(alignX); | 262 alignX = SkScalarHalf(alignX); |
262 alignY = SkScalarHalf(alignY); | 263 alignY = SkScalarHalf(alignY); |
263 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { | 264 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { |
264 alignX = 0; | 265 alignX = 0; |
265 alignY = 0; | 266 alignY = 0; |
266 } | 267 } |
267 x -= alignX; | 268 x -= alignX; |
268 y -= alignY; | 269 y -= alignY; |
269 SkPoint offset = SkPoint::Make(x, y); | 270 SkPoint offset = SkPoint::Make(x, y); |
270 | 271 |
271 this->drawPosText(rt, paint, skPaint, viewMatrix, text, byteLength, position
s.begin(), 2, | 272 this->drawPosText(rt, clip, paint, skPaint, viewMatrix, text, byteLength, po
sitions.begin(), 2, |
272 offset); | 273 offset); |
273 } | 274 } |
274 | 275 |
275 void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrPaint
& paint, | 276 void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip&
clip, |
| 277 const GrPaint& paint, |
276 const SkPaint& skPaint, const SkM
atrix& viewMatrix, | 278 const SkPaint& skPaint, const SkM
atrix& viewMatrix, |
277 const char text[], size_t byteLen
gth, | 279 const char text[], size_t byteLen
gth, |
278 const SkScalar pos[], int scalars
PerPosition, | 280 const SkScalar pos[], int scalars
PerPosition, |
279 const SkPoint& offset) { | 281 const SkPoint& offset) { |
280 | 282 |
281 SkASSERT(byteLength == 0 || text != NULL); | 283 SkASSERT(byteLength == 0 || text != NULL); |
282 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 284 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
283 | 285 |
284 // nothing to draw | 286 // nothing to draw |
285 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/)
{ | 287 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/)
{ |
286 return; | 288 return; |
287 } | 289 } |
288 | 290 |
289 fViewMatrix = viewMatrix; | 291 fViewMatrix = viewMatrix; |
290 this->init(rt, paint, skPaint); | 292 this->init(rt, clip, paint, skPaint); |
291 | 293 |
292 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 294 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
293 | 295 |
294 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); | 296 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); |
295 SkGlyphCache* cache = autoCache.getCache(); | 297 SkGlyphCache* cache = autoCache.getCache(); |
296 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 298 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
297 | 299 |
298 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); | 300 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); |
299 | 301 |
300 int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL); | 302 int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 } | 357 } |
356 } | 358 } |
357 } | 359 } |
358 pos += scalarsPerPosition; | 360 pos += scalarsPerPosition; |
359 } | 361 } |
360 } | 362 } |
361 | 363 |
362 this->finish(); | 364 this->finish(); |
363 | 365 |
364 if (fallbackTxt.count() > 0) { | 366 if (fallbackTxt.count() > 0) { |
365 fFallbackTextContext->drawPosText(rt, paint, skPaint, viewMatrix, fallba
ckTxt.begin(), | 367 fFallbackTextContext->drawPosText(rt, clip, paint, skPaint, viewMatrix,
fallbackTxt.begin(), |
366 fallbackTxt.count(), fallbackPos.begin
(), | 368 fallbackTxt.count(), fallbackPos.begin
(), |
367 scalarsPerPosition, offset); | 369 scalarsPerPosition, offset); |
368 } | 370 } |
369 } | 371 } |
370 | 372 |
371 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { | 373 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { |
372 unsigned r = SkColorGetR(c); | 374 unsigned r = SkColorGetR(c); |
373 unsigned g = SkColorGetG(c); | 375 unsigned g = SkColorGetG(c); |
374 unsigned b = SkColorGetB(c); | 376 unsigned b = SkColorGetB(c); |
375 return GrColorPackRGBA(r, g, b, 0xff); | 377 return GrColorPackRGBA(r, g, b, 0xff); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 this->flush(); | 566 this->flush(); |
565 | 567 |
566 SkMatrix ctm; | 568 SkMatrix ctm; |
567 ctm.setScale(fTextRatio, fTextRatio); | 569 ctm.setScale(fTextRatio, fTextRatio); |
568 ctm.postTranslate(sx - dx, sy - dy); | 570 ctm.postTranslate(sx - dx, sy - dy); |
569 | 571 |
570 SkPath tmpPath(*glyph->fPath); | 572 SkPath tmpPath(*glyph->fPath); |
571 tmpPath.transform(ctm); | 573 tmpPath.transform(ctm); |
572 | 574 |
573 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); | 575 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); |
574 fContext->drawPath(fRenderTarget, fPaint, fViewMatrix, tmpPath, stro
keInfo); | 576 fContext->drawPath(fRenderTarget, fClip, fPaint, fViewMatrix, tmpPat
h, strokeInfo); |
575 | 577 |
576 // remove this glyph from the vertices we need to allocate | 578 // remove this glyph from the vertices we need to allocate |
577 fTotalVertexCount -= kVerticesPerGlyph; | 579 fTotalVertexCount -= kVerticesPerGlyph; |
578 return true; | 580 return true; |
579 } | 581 } |
580 } | 582 } |
581 | 583 |
582 SkASSERT(glyph->fPlot); | 584 SkASSERT(glyph->fPlot); |
583 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); | 585 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); |
584 glyph->fPlot->setDrawToken(drawToken); | 586 glyph->fPlot->setDrawToken(drawToken); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 } | 717 } |
716 } | 718 } |
717 | 719 |
718 inline void GrDistanceFieldTextContext::finish() { | 720 inline void GrDistanceFieldTextContext::finish() { |
719 this->flush(); | 721 this->flush(); |
720 fTotalVertexCount = 0; | 722 fTotalVertexCount = 0; |
721 | 723 |
722 GrTextContext::finish(); | 724 GrTextContext::finish(); |
723 } | 725 } |
724 | 726 |
OLD | NEW |