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 "GrAtlasTextContext.h" | 10 #include "GrAtlasTextContext.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 fPaint.setColor(GrColorPackRGBA(0x7F, 0x00, 0x00, 0xFF)); | 264 fPaint.setColor(GrColorPackRGBA(0x7F, 0x00, 0x00, 0xFF)); |
265 #endif | 265 #endif |
266 } | 266 } |
267 | 267 |
268 fUseLCDText = fSkPaint.isLCDRenderText(); | 268 fUseLCDText = fSkPaint.isLCDRenderText(); |
269 | 269 |
270 fSkPaint.setLCDRenderText(false); | 270 fSkPaint.setLCDRenderText(false); |
271 fSkPaint.setAutohinted(false); | 271 fSkPaint.setAutohinted(false); |
272 fSkPaint.setHinting(SkPaint::kNormal_Hinting); | 272 fSkPaint.setHinting(SkPaint::kNormal_Hinting); |
273 fSkPaint.setSubpixelText(true); | 273 fSkPaint.setSubpixelText(true); |
274 | |
275 // fix for skia:3528 | |
276 // if we're scaling up, include any scaling to match text size in the view m
atrix | |
277 if (fTextRatio > 1.0f) { | |
278 fViewMatrix.preScale(fTextRatio, fTextRatio); | |
279 } | |
280 } | 274 } |
281 | 275 |
282 void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrClip& cl
ip, | 276 void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrClip& cl
ip, |
283 const GrPaint& paint, | 277 const GrPaint& paint, |
284 const SkPaint& skPaint, const SkMatr
ix& viewMatrix, | 278 const SkPaint& skPaint, const SkMatr
ix& viewMatrix, |
285 const char text[], size_t byteLength
, | 279 const char text[], size_t byteLength
, |
286 SkScalar x, SkScalar y, | 280 SkScalar x, SkScalar y, |
287 const SkIRect& regionClipBounds) { | 281 const SkIRect& regionClipBounds) { |
288 SkASSERT(byteLength == 0 || text != NULL); | 282 SkASSERT(byteLength == 0 || text != NULL); |
289 | 283 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 const SkMatrix& ctm = fViewMatrix; | 476 const SkMatrix& ctm = fViewMatrix; |
483 | 477 |
484 // set up any flags | 478 // set up any flags |
485 uint32_t flags = 0; | 479 uint32_t flags = 0; |
486 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; | 480 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
487 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; | 481 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; |
488 flags |= fUseLCDText && ctm.rectStaysRect() ? | 482 flags |= fUseLCDText && ctm.rectStaysRect() ? |
489 kRectToRect_DistanceFieldEffectFlag : 0; | 483 kRectToRect_DistanceFieldEffectFlag : 0; |
490 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); | 484 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); |
491 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; | 485 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; |
492 | 486 |
493 // fix for skia:3528 | |
494 // set the local matrix to correct any text size scaling for gradients et al
. | |
495 SkMatrix localMatrix; | |
496 if (fTextRatio > 1.0f) { | |
497 localMatrix.setScale(fTextRatio, fTextRatio); | |
498 } else { | |
499 localMatrix.reset(); | |
500 } | |
501 | |
502 // see if we need to create a new effect | 487 // see if we need to create a new effect |
503 if (textureUniqueID != fEffectTextureUniqueID || | 488 if (textureUniqueID != fEffectTextureUniqueID || |
504 filteredColor != fEffectColor || | 489 filteredColor != fEffectColor || |
505 flags != fEffectFlags || | 490 flags != fEffectFlags || |
506 !fCachedGeometryProcessor->viewMatrix().cheapEqualTo(fViewMatrix) || | 491 !fCachedGeometryProcessor->viewMatrix().cheapEqualTo(fViewMatrix)) { |
507 !fCachedGeometryProcessor->localMatrix().cheapEqualTo(localMatrix)) { | |
508 GrColor color = fPaint.getColor(); | 492 GrColor color = fPaint.getColor(); |
509 | |
510 if (fUseLCDText) { | 493 if (fUseLCDText) { |
511 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); | 494 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol
or); |
512 | 495 |
513 float redCorrection = | 496 float redCorrection = |
514 fDistanceAdjustTable[GrColorUnpackR(colorNoPreMul) >> kDistanceA
djustLumShift]; | 497 fDistanceAdjustTable[GrColorUnpackR(colorNoPreMul) >> kDistanceA
djustLumShift]; |
515 float greenCorrection = | 498 float greenCorrection = |
516 fDistanceAdjustTable[GrColorUnpackG(colorNoPreMul) >> kDistanceA
djustLumShift]; | 499 fDistanceAdjustTable[GrColorUnpackG(colorNoPreMul) >> kDistanceA
djustLumShift]; |
517 float blueCorrection = | 500 float blueCorrection = |
518 fDistanceAdjustTable[GrColorUnpackB(colorNoPreMul) >> kDistanceA
djustLumShift]; | 501 fDistanceAdjustTable[GrColorUnpackB(colorNoPreMul) >> kDistanceA
djustLumShift]; |
519 GrDistanceFieldLCDTextureEffect::DistanceAdjust widthAdjust = | 502 GrDistanceFieldLCDTextureEffect::DistanceAdjust widthAdjust = |
520 GrDistanceFieldLCDTextureEffect::DistanceAdjust::Make(redCorrect
ion, | 503 GrDistanceFieldLCDTextureEffect::DistanceAdjust::Make(redCorrect
ion, |
521 greenCorrecti
on, | 504 greenCorrecti
on, |
522 blueCorrectio
n); | 505 blueCorrectio
n); |
523 fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Crea
te(color, | 506 fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Crea
te(color, |
524
fViewMatrix, | 507
fViewMatrix, |
525
localMatrix, | |
526
fCurrTexture, | 508
fCurrTexture, |
527
params, | 509
params, |
528
widthAdjust, | 510
widthAdjust, |
529
flags)); | 511
flags)); |
530 } else { | 512 } else { |
531 flags |= kColorAttr_DistanceFieldEffectFlag; | 513 flags |= kColorAttr_DistanceFieldEffectFlag; |
532 bool opaque = GrColorIsOpaque(color); | 514 bool opaque = GrColorIsOpaque(color); |
533 #ifdef SK_GAMMA_APPLY_TO_A8 | 515 #ifdef SK_GAMMA_APPLY_TO_A8 |
534 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie
s.gamma(), | 516 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie
s.gamma(), |
535 filteredColor); | 517 filteredColor); |
536 float correction = fDistanceAdjustTable[lum >> kDistanceAdjustLumShi
ft]; | 518 float correction = fDistanceAdjustTable[lum >> kDistanceAdjustLumShi
ft]; |
537 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(
color, | 519 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(
color, |
538
fViewMatrix, | 520
fViewMatrix, |
539
localMatrix, | |
540
fCurrTexture, | 521
fCurrTexture, |
541
params, | 522
params, |
542
correction, | 523
correction, |
543
flags, | 524
flags, |
544
opaque)); | 525
opaque)); |
545 #else | 526 #else |
546 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(
color, | 527 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create(
color, |
547
fViewMatrix, | 528
fViewMatrix, |
548
localMatrix, | |
549
fCurrTexture, | 529
fCurrTexture, |
550
params, | 530
params, |
551
flags, | 531
flags, |
552
opaque)); | 532
opaque)); |
553 #endif | 533 #endif |
554 } | 534 } |
555 fEffectTextureUniqueID = textureUniqueID; | 535 fEffectTextureUniqueID = textureUniqueID; |
556 fEffectColor = filteredColor; | 536 fEffectColor = filteredColor; |
557 fEffectFlags = flags; | 537 fEffectFlags = flags; |
558 } | 538 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 if (kA8_GrMaskFormat != glyph->fMaskFormat) { | 597 if (kA8_GrMaskFormat != glyph->fMaskFormat) { |
618 return false; | 598 return false; |
619 } | 599 } |
620 | 600 |
621 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); | 601 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); |
622 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); | 602 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); |
623 SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldIn
set); | 603 SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldIn
set); |
624 SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceField
Inset); | 604 SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceField
Inset); |
625 | 605 |
626 SkScalar scale = fTextRatio; | 606 SkScalar scale = fTextRatio; |
627 // if we're scaling up, using fix for skia:3528 | 607 dx *= scale; |
628 if (scale > 1.0f) { | 608 dy *= scale; |
629 sx /= scale; | |
630 sy /= scale; | |
631 } else { | |
632 dx *= scale; | |
633 dy *= scale; | |
634 width *= scale; | |
635 height *= scale; | |
636 } | |
637 sx += dx; | 609 sx += dx; |
638 sy += dy; | 610 sy += dy; |
| 611 width *= scale; |
| 612 height *= scale; |
639 SkRect glyphRect = SkRect::MakeXYWH(sx, sy, width, height); | 613 SkRect glyphRect = SkRect::MakeXYWH(sx, sy, width, height); |
640 | 614 |
641 // check if we clipped out | 615 // check if we clipped out |
642 SkRect dstRect; | 616 SkRect dstRect; |
643 const SkMatrix& ctm = fViewMatrix; | 617 const SkMatrix& ctm = fViewMatrix; |
644 (void) ctm.mapRect(&dstRect, glyphRect); | 618 (void) ctm.mapRect(&dstRect, glyphRect); |
645 if (fClipRect.quickReject(SkScalarTruncToInt(dstRect.left()), | 619 if (fClipRect.quickReject(SkScalarTruncToInt(dstRect.left()), |
646 SkScalarTruncToInt(dstRect.top()), | 620 SkScalarTruncToInt(dstRect.top()), |
647 SkScalarTruncToInt(dstRect.right()), | 621 SkScalarTruncToInt(dstRect.right()), |
648 SkScalarTruncToInt(dstRect.bottom()))) { | 622 SkScalarTruncToInt(dstRect.bottom()))) { |
(...skipping 13 matching lines...) Expand all Loading... |
662 delete path; | 636 delete path; |
663 return true; | 637 return true; |
664 } | 638 } |
665 glyph->fPath = path; | 639 glyph->fPath = path; |
666 } | 640 } |
667 | 641 |
668 // flush any accumulated draws before drawing this glyph as a path. | 642 // flush any accumulated draws before drawing this glyph as a path. |
669 this->flush(); | 643 this->flush(); |
670 | 644 |
671 SkMatrix ctm; | 645 SkMatrix ctm; |
| 646 ctm.setScale(fTextRatio, fTextRatio); |
672 ctm.postTranslate(sx - dx, sy - dy); | 647 ctm.postTranslate(sx - dx, sy - dy); |
673 | 648 |
674 SkPath tmpPath(*glyph->fPath); | 649 SkPath tmpPath(*glyph->fPath); |
675 tmpPath.transform(ctm); | 650 tmpPath.transform(ctm); |
676 | 651 |
677 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); | 652 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); |
678 fContext->drawPath(fRenderTarget, fClip, fPaint, fViewMatrix, tmpPat
h, strokeInfo); | 653 fContext->drawPath(fRenderTarget, fClip, fPaint, fViewMatrix, tmpPat
h, strokeInfo); |
679 | 654 |
680 // remove this glyph from the vertices we need to allocate | 655 // remove this glyph from the vertices we need to allocate |
681 fTotalVertexCount -= kVerticesPerGlyph; | 656 fTotalVertexCount -= kVerticesPerGlyph; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 } | 794 } |
820 } | 795 } |
821 | 796 |
822 inline void GrDistanceFieldTextContext::finish() { | 797 inline void GrDistanceFieldTextContext::finish() { |
823 this->flush(); | 798 this->flush(); |
824 fTotalVertexCount = 0; | 799 fTotalVertexCount = 0; |
825 | 800 |
826 GrTextContext::finish(); | 801 GrTextContext::finish(); |
827 } | 802 } |
828 | 803 |
OLD | NEW |