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