Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Side by Side Diff: src/gpu/GrDistanceFieldTextContext.cpp

Issue 1029423003: Calculate inverse scale for distance fields in vertex shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix gradients and textalign issues Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // include any scaling to match text size in the view matrix
276 fViewMatrix.preScale(fTextRatio, fTextRatio);
274 } 277 }
275 278
276 void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrClip& cl ip, 279 void GrDistanceFieldTextContext::onDrawText(GrRenderTarget* rt, const GrClip& cl ip,
277 const GrPaint& paint, 280 const GrPaint& paint,
278 const SkPaint& skPaint, const SkMatr ix& viewMatrix, 281 const SkPaint& skPaint, const SkMatr ix& viewMatrix,
279 const char text[], size_t byteLength , 282 const char text[], size_t byteLength ,
280 SkScalar x, SkScalar y, 283 SkScalar x, SkScalar y,
281 const SkIRect& regionClipBounds) { 284 const SkIRect& regionClipBounds) {
282 SkASSERT(byteLength == 0 || text != NULL); 285 SkASSERT(byteLength == 0 || text != NULL);
283 286
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 const SkMatrix& ctm = fViewMatrix; 479 const SkMatrix& ctm = fViewMatrix;
477 480
478 // set up any flags 481 // set up any flags
479 uint32_t flags = 0; 482 uint32_t flags = 0;
480 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; 483 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
481 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0; 484 flags |= fUseLCDText ? kUseLCD_DistanceFieldEffectFlag : 0;
482 flags |= fUseLCDText && ctm.rectStaysRect() ? 485 flags |= fUseLCDText && ctm.rectStaysRect() ?
483 kRectToRect_DistanceFieldEffectFlag : 0; 486 kRectToRect_DistanceFieldEffectFlag : 0;
484 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry()); 487 bool useBGR = SkPixelGeometryIsBGR(fDeviceProperties.pixelGeometry());
485 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0; 488 flags |= fUseLCDText && useBGR ? kBGR_DistanceFieldEffectFlag : 0;
486 489
490 // set the local matrix to correct any text size scaling for gradients et al .
491 SkMatrix localMatrix;
492 localMatrix.setScale(fTextRatio, fTextRatio);
493
487 // see if we need to create a new effect 494 // see if we need to create a new effect
488 if (textureUniqueID != fEffectTextureUniqueID || 495 if (textureUniqueID != fEffectTextureUniqueID ||
489 filteredColor != fEffectColor || 496 filteredColor != fEffectColor ||
490 flags != fEffectFlags || 497 flags != fEffectFlags ||
491 !fCachedGeometryProcessor->viewMatrix().cheapEqualTo(fViewMatrix)) { 498 !fCachedGeometryProcessor->viewMatrix().cheapEqualTo(fViewMatrix) ||
499 !fCachedGeometryProcessor->localMatrix().cheapEqualTo(localMatrix)) {
492 GrColor color = fPaint.getColor(); 500 GrColor color = fPaint.getColor();
501
493 if (fUseLCDText) { 502 if (fUseLCDText) {
494 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol or); 503 GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredCol or);
495 504
496 float redCorrection = 505 float redCorrection =
497 fDistanceAdjustTable[GrColorUnpackR(colorNoPreMul) >> kDistanceA djustLumShift]; 506 fDistanceAdjustTable[GrColorUnpackR(colorNoPreMul) >> kDistanceA djustLumShift];
498 float greenCorrection = 507 float greenCorrection =
499 fDistanceAdjustTable[GrColorUnpackG(colorNoPreMul) >> kDistanceA djustLumShift]; 508 fDistanceAdjustTable[GrColorUnpackG(colorNoPreMul) >> kDistanceA djustLumShift];
500 float blueCorrection = 509 float blueCorrection =
501 fDistanceAdjustTable[GrColorUnpackB(colorNoPreMul) >> kDistanceA djustLumShift]; 510 fDistanceAdjustTable[GrColorUnpackB(colorNoPreMul) >> kDistanceA djustLumShift];
502 GrDistanceFieldLCDTextureEffect::DistanceAdjust widthAdjust = 511 GrDistanceFieldLCDTextureEffect::DistanceAdjust widthAdjust =
503 GrDistanceFieldLCDTextureEffect::DistanceAdjust::Make(redCorrect ion, 512 GrDistanceFieldLCDTextureEffect::DistanceAdjust::Make(redCorrect ion,
504 greenCorrecti on, 513 greenCorrecti on,
505 blueCorrectio n); 514 blueCorrectio n);
506 fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Crea te(color, 515 fCachedGeometryProcessor.reset(GrDistanceFieldLCDTextureEffect::Crea te(color,
507 fViewMatrix, 516 fViewMatrix,
517 localMatrix,
508 fCurrTexture, 518 fCurrTexture,
509 params, 519 params,
510 widthAdjust, 520 widthAdjust,
511 flags)); 521 flags));
512 } else { 522 } else {
513 flags |= kColorAttr_DistanceFieldEffectFlag; 523 flags |= kColorAttr_DistanceFieldEffectFlag;
514 bool opaque = GrColorIsOpaque(color); 524 bool opaque = GrColorIsOpaque(color);
515 #ifdef SK_GAMMA_APPLY_TO_A8 525 #ifdef SK_GAMMA_APPLY_TO_A8
516 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie s.gamma(), 526 U8CPU lum = SkColorSpaceLuminance::computeLuminance(fDevicePropertie s.gamma(),
517 filteredColor); 527 filteredColor);
518 float correction = fDistanceAdjustTable[lum >> kDistanceAdjustLumShi ft]; 528 float correction = fDistanceAdjustTable[lum >> kDistanceAdjustLumShi ft];
519 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create( color, 529 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create( color,
520 fViewMatrix, 530 fViewMatrix,
531 localMatrix,
521 fCurrTexture, 532 fCurrTexture,
522 params, 533 params,
523 correction, 534 correction,
524 flags, 535 flags,
525 opaque)); 536 opaque));
526 #else 537 #else
527 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create( color, 538 fCachedGeometryProcessor.reset(GrDistanceFieldTextureEffect::Create( color,
528 fViewMatrix, 539 fViewMatrix,
540 localMatrix,
529 fCurrTexture, 541 fCurrTexture,
530 params, 542 params,
531 flags, 543 flags,
532 opaque)); 544 opaque));
533 #endif 545 #endif
534 } 546 }
535 fEffectTextureUniqueID = textureUniqueID; 547 fEffectTextureUniqueID = textureUniqueID;
536 fEffectColor = filteredColor; 548 fEffectColor = filteredColor;
537 fEffectFlags = flags; 549 fEffectFlags = flags;
538 } 550 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 if (kA8_GrMaskFormat != glyph->fMaskFormat) { 609 if (kA8_GrMaskFormat != glyph->fMaskFormat) {
598 return false; 610 return false;
599 } 611 }
600 612
601 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); 613 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset);
602 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); 614 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset);
603 SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldIn set); 615 SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldIn set);
604 SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceField Inset); 616 SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceField Inset);
605 617
606 SkScalar scale = fTextRatio; 618 SkScalar scale = fTextRatio;
607 dx *= scale; 619 sx /= scale;
608 dy *= scale; 620 sy /= scale;
609 sx += dx; 621 sx += dx;
610 sy += dy; 622 sy += dy;
611 width *= scale;
612 height *= scale;
613 SkRect glyphRect = SkRect::MakeXYWH(sx, sy, width, height); 623 SkRect glyphRect = SkRect::MakeXYWH(sx, sy, width, height);
614 624
615 // check if we clipped out 625 // check if we clipped out
616 SkRect dstRect; 626 SkRect dstRect;
617 const SkMatrix& ctm = fViewMatrix; 627 const SkMatrix& ctm = fViewMatrix;
618 (void) ctm.mapRect(&dstRect, glyphRect); 628 (void) ctm.mapRect(&dstRect, glyphRect);
619 if (fClipRect.quickReject(SkScalarTruncToInt(dstRect.left()), 629 if (fClipRect.quickReject(SkScalarTruncToInt(dstRect.left()),
620 SkScalarTruncToInt(dstRect.top()), 630 SkScalarTruncToInt(dstRect.top()),
621 SkScalarTruncToInt(dstRect.right()), 631 SkScalarTruncToInt(dstRect.right()),
622 SkScalarTruncToInt(dstRect.bottom()))) { 632 SkScalarTruncToInt(dstRect.bottom()))) {
(...skipping 13 matching lines...) Expand all
636 delete path; 646 delete path;
637 return true; 647 return true;
638 } 648 }
639 glyph->fPath = path; 649 glyph->fPath = path;
640 } 650 }
641 651
642 // flush any accumulated draws before drawing this glyph as a path. 652 // flush any accumulated draws before drawing this glyph as a path.
643 this->flush(); 653 this->flush();
644 654
645 SkMatrix ctm; 655 SkMatrix ctm;
646 ctm.setScale(fTextRatio, fTextRatio);
647 ctm.postTranslate(sx - dx, sy - dy); 656 ctm.postTranslate(sx - dx, sy - dy);
648 657
649 SkPath tmpPath(*glyph->fPath); 658 SkPath tmpPath(*glyph->fPath);
650 tmpPath.transform(ctm); 659 tmpPath.transform(ctm);
651 660
652 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); 661 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle);
653 fContext->drawPath(fRenderTarget, fClip, fPaint, fViewMatrix, tmpPat h, strokeInfo); 662 fContext->drawPath(fRenderTarget, fClip, fPaint, fViewMatrix, tmpPat h, strokeInfo);
654 663
655 // remove this glyph from the vertices we need to allocate 664 // remove this glyph from the vertices we need to allocate
656 fTotalVertexCount -= kVerticesPerGlyph; 665 fTotalVertexCount -= kVerticesPerGlyph;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 } 803 }
795 } 804 }
796 805
797 inline void GrDistanceFieldTextContext::finish() { 806 inline void GrDistanceFieldTextContext::finish() {
798 this->flush(); 807 this->flush();
799 fTotalVertexCount = 0; 808 fTotalVertexCount = 0;
800 809
801 GrTextContext::finish(); 810 GrTextContext::finish();
802 } 811 }
803 812
OLDNEW
« no previous file with comments | « no previous file | src/gpu/effects/GrDistanceFieldTextureEffect.h » ('j') | src/gpu/effects/GrDistanceFieldTextureEffect.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698