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

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

Issue 1031423002: Add mixedtextblob gm and a simple bench (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: mac warnings 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
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 #include "GrAtlasTextContext.h" 7 #include "GrAtlasTextContext.h"
8 8
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrBatch.h" 10 #include "GrBatch.h"
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 361
362 if (glyph.fWidth) { 362 if (glyph.fWidth) {
363 this->appendGlyph(blob, 363 this->appendGlyph(blob,
364 runIndex, 364 runIndex,
365 GrGlyph::Pack(glyph.getGlyphID(), 365 GrGlyph::Pack(glyph.getGlyphID(),
366 glyph.getSubXFixed(), 366 glyph.getSubXFixed(),
367 glyph.getSubYFixed(), 367 glyph.getSubYFixed(),
368 GrGlyph::kCoverage_MaskStyle), 368 GrGlyph::kCoverage_MaskStyle),
369 Sk48Dot16FloorToInt(fx), 369 Sk48Dot16FloorToInt(fx),
370 Sk48Dot16FloorToInt(fy), 370 Sk48Dot16FloorToInt(fy),
371 skPaint.getColor(),
371 fontScaler, 372 fontScaler,
372 clipRect); 373 clipRect);
373 } 374 }
374 375
375 fx += glyph.fAdvanceX; 376 fx += glyph.fAdvanceX;
376 fy += glyph.fAdvanceY; 377 fy += glyph.fAdvanceY;
377 } 378 }
378 } 379 }
379 380
380 void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, 381 void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 453
453 if (glyph.fWidth) { 454 if (glyph.fWidth) {
454 this->appendGlyph(blob, 455 this->appendGlyph(blob,
455 runIndex, 456 runIndex,
456 GrGlyph::Pack(glyph.getGlyphID(), 457 GrGlyph::Pack(glyph.getGlyphID(),
457 glyph.getSubXFixed(), 458 glyph.getSubXFixed(),
458 glyph.getSubYFixed(), 459 glyph.getSubYFixed(),
459 GrGlyph::kCoverage_MaskStyle ), 460 GrGlyph::kCoverage_MaskStyle ),
460 Sk48Dot16FloorToInt(fx), 461 Sk48Dot16FloorToInt(fx),
461 Sk48Dot16FloorToInt(fy), 462 Sk48Dot16FloorToInt(fy),
463 skPaint.getColor(),
462 fontScaler, 464 fontScaler,
463 clipRect); 465 clipRect);
464 } 466 }
465 pos += scalarsPerPosition; 467 pos += scalarsPerPosition;
466 } 468 }
467 } else { 469 } else {
468 while (text < stop) { 470 while (text < stop) {
469 const char* currentText = text; 471 const char* currentText = text;
470 const SkGlyph& metricGlyph = glyphCacheProc(cache, &text, 0, 0); 472 const SkGlyph& metricGlyph = glyphCacheProc(cache, &text, 0, 0);
471 473
(...skipping 17 matching lines...) Expand all
489 SkASSERT(glyph.fWidth); 491 SkASSERT(glyph.fWidth);
490 492
491 this->appendGlyph(blob, 493 this->appendGlyph(blob,
492 runIndex, 494 runIndex,
493 GrGlyph::Pack(glyph.getGlyphID(), 495 GrGlyph::Pack(glyph.getGlyphID(),
494 glyph.getSubXFixed(), 496 glyph.getSubXFixed(),
495 glyph.getSubYFixed(), 497 glyph.getSubYFixed(),
496 GrGlyph::kCoverage_MaskStyle ), 498 GrGlyph::kCoverage_MaskStyle ),
497 Sk48Dot16FloorToInt(fx), 499 Sk48Dot16FloorToInt(fx),
498 Sk48Dot16FloorToInt(fy), 500 Sk48Dot16FloorToInt(fy),
501 skPaint.getColor(),
499 fontScaler, 502 fontScaler,
500 clipRect); 503 clipRect);
501 } 504 }
502 pos += scalarsPerPosition; 505 pos += scalarsPerPosition;
503 } 506 }
504 } 507 }
505 } else { // not subpixel 508 } else { // not subpixel
506 509
507 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { 510 if (SkPaint::kLeft_Align == skPaint.getTextAlign()) {
508 while (text < stop) { 511 while (text < stop) {
509 // the last 2 parameters are ignored 512 // the last 2 parameters are ignored
510 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 513 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
511 514
512 if (glyph.fWidth) { 515 if (glyph.fWidth) {
513 SkPoint tmsLoc; 516 SkPoint tmsLoc;
514 tmsProc(pos, &tmsLoc); 517 tmsProc(pos, &tmsLoc);
515 518
516 Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + SK_ScalarHalf); //halfSampleX; 519 Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + SK_ScalarHalf); //halfSampleX;
517 Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + SK_ScalarHalf); //halfSampleY; 520 Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + SK_ScalarHalf); //halfSampleY;
518 this->appendGlyph(blob, 521 this->appendGlyph(blob,
519 runIndex, 522 runIndex,
520 GrGlyph::Pack(glyph.getGlyphID(), 523 GrGlyph::Pack(glyph.getGlyphID(),
521 glyph.getSubXFixed(), 524 glyph.getSubXFixed(),
522 glyph.getSubYFixed(), 525 glyph.getSubYFixed(),
523 GrGlyph::kCoverage_MaskStyle ), 526 GrGlyph::kCoverage_MaskStyle ),
524 Sk48Dot16FloorToInt(fx), 527 Sk48Dot16FloorToInt(fx),
525 Sk48Dot16FloorToInt(fy), 528 Sk48Dot16FloorToInt(fy),
529 skPaint.getColor(),
526 fontScaler, 530 fontScaler,
527 clipRect); 531 clipRect);
528 } 532 }
529 pos += scalarsPerPosition; 533 pos += scalarsPerPosition;
530 } 534 }
531 } else { 535 } else {
532 while (text < stop) { 536 while (text < stop) {
533 // the last 2 parameters are ignored 537 // the last 2 parameters are ignored
534 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 538 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
535 539
536 if (glyph.fWidth) { 540 if (glyph.fWidth) {
537 SkPoint tmsLoc; 541 SkPoint tmsLoc;
538 tmsProc(pos, &tmsLoc); 542 tmsProc(pos, &tmsLoc);
539 543
540 SkPoint alignLoc; 544 SkPoint alignLoc;
541 alignProc(tmsLoc, glyph, &alignLoc); 545 alignProc(tmsLoc, glyph, &alignLoc);
542 546
543 Sk48Dot16 fx = SkScalarTo48Dot16(alignLoc.fX + SK_ScalarHalf ); //halfSampleX; 547 Sk48Dot16 fx = SkScalarTo48Dot16(alignLoc.fX + SK_ScalarHalf ); //halfSampleX;
544 Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + SK_ScalarHalf ); //halfSampleY; 548 Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + SK_ScalarHalf ); //halfSampleY;
545 this->appendGlyph(blob, 549 this->appendGlyph(blob,
546 runIndex, 550 runIndex,
547 GrGlyph::Pack(glyph.getGlyphID(), 551 GrGlyph::Pack(glyph.getGlyphID(),
548 glyph.getSubXFixed(), 552 glyph.getSubXFixed(),
549 glyph.getSubYFixed(), 553 glyph.getSubYFixed(),
550 GrGlyph::kCoverage_MaskStyle ), 554 GrGlyph::kCoverage_MaskStyle ),
551 Sk48Dot16FloorToInt(fx), 555 Sk48Dot16FloorToInt(fx),
552 Sk48Dot16FloorToInt(fy), 556 Sk48Dot16FloorToInt(fy),
557 skPaint.getColor(),
553 fontScaler, 558 fontScaler,
554 clipRect); 559 clipRect);
555 } 560 }
556 pos += scalarsPerPosition; 561 pos += scalarsPerPosition;
557 } 562 }
558 } 563 }
559 } 564 }
560 } 565 }
561 566
562 void GrAtlasTextContext::appendGlyph(BitmapTextBlob* blob, int runIndex, GrGlyph ::PackedID packed, 567 void GrAtlasTextContext::appendGlyph(BitmapTextBlob* blob, int runIndex, GrGlyph ::PackedID packed,
563 int vx, int vy, GrFontScaler* scaler, 568 int vx, int vy, GrColor color, GrFontScaler * scaler,
564 const SkIRect& clipRect) { 569 const SkIRect& clipRect) {
565 if (NULL == fCurrStrike) { 570 if (NULL == fCurrStrike) {
566 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); 571 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler);
567 } 572 }
568 573
569 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); 574 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler);
570 if (NULL == glyph || glyph->fBounds.isEmpty()) { 575 if (NULL == glyph || glyph->fBounds.isEmpty()) {
571 return; 576 return;
572 } 577 }
573 578
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 626
622 size_t vertexStride = get_vertex_stride(format); 627 size_t vertexStride = get_vertex_stride(format);
623 628
624 SkRect r; 629 SkRect r;
625 r.fLeft = SkIntToScalar(x); 630 r.fLeft = SkIntToScalar(x);
626 r.fTop = SkIntToScalar(y); 631 r.fTop = SkIntToScalar(y);
627 r.fRight = r.fLeft + SkIntToScalar(width); 632 r.fRight = r.fLeft + SkIntToScalar(width);
628 r.fBottom = r.fTop + SkIntToScalar(height); 633 r.fBottom = r.fTop + SkIntToScalar(height);
629 634
630 run.fVertexBounds.joinNonEmptyArg(r); 635 run.fVertexBounds.joinNonEmptyArg(r);
631 GrColor color = fPaint.getColor();
632 run.fColor = color; 636 run.fColor = color;
633 637
634 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->fVert exEndIndex); 638 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->fVert exEndIndex);
635 639
636 // V0 640 // V0
637 SkPoint* position = reinterpret_cast<SkPoint*>(vertex); 641 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
638 position->set(r.fLeft, r.fTop); 642 position->set(r.fLeft, r.fTop);
639 if (kA8_GrMaskFormat == format) { 643 if (kA8_GrMaskFormat == format) {
640 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)) ; 644 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)) ;
641 *colorPtr = color; 645 *colorPtr = color;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline ) override { 742 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline ) override {
739 // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix. 743 // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix.
740 // TODO actually only invert if we don't have RGBA 744 // TODO actually only invert if we don't have RGBA
741 SkMatrix localMatrix; 745 SkMatrix localMatrix;
742 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) { 746 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) {
743 SkDebugf("Cannot invert viewmatrix\n"); 747 SkDebugf("Cannot invert viewmatrix\n");
744 return; 748 return;
745 } 749 }
746 750
747 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone _FilterMode); 751 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone _FilterMode);
752
748 // This will be ignored in the non A8 case 753 // This will be ignored in the non A8 case
749 bool opaqueVertexColors = GrColorIsOpaque(this->color()); 754 bool opaqueVertexColors = GrColorIsOpaque(this->color());
750 SkAutoTUnref<const GrGeometryProcessor> gp( 755 SkAutoTUnref<const GrGeometryProcessor> gp(
751 GrBitmapTextGeoProc::Create(this->color(), 756 GrBitmapTextGeoProc::Create(this->color(),
752 fFontCache->getTexture(fMaskFormat), 757 fFontCache->getTexture(fMaskFormat),
753 params, 758 params,
754 fMaskFormat, 759 fMaskFormat,
755 opaqueVertexColors, 760 opaqueVertexColors,
756 localMatrix)); 761 localMatrix));
757 762
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 GrColor color = paint.getColor(); 1024 GrColor color = paint.getColor();
1020 for (uint32_t run = 0; run < blob->fRunCount; run++) { 1025 for (uint32_t run = 0; run < blob->fRunCount; run++) {
1021 for (int subRun = 0; subRun < blob->fRuns[run].fSubRunInfo.count(); subR un++) { 1026 for (int subRun = 0; subRun < blob->fRuns[run].fSubRunInfo.count(); subR un++) {
1022 PerSubRunInfo& info = blob->fRuns[run].fSubRunInfo[subRun]; 1027 PerSubRunInfo& info = blob->fRuns[run].fSubRunInfo[subRun];
1023 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; 1028 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex;
1024 if (0 == glyphCount) { 1029 if (0 == glyphCount) {
1025 continue; 1030 continue;
1026 } 1031 }
1027 1032
1028 GrMaskFormat format = info.fMaskFormat; 1033 GrMaskFormat format = info.fMaskFormat;
1029 if (kARGB_GrMaskFormat == format) { 1034 GrColor subRunColor = kARGB_GrMaskFormat == format ?
1030 color = SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paint Alpha); 1035 SkColorSetARGB(paintAlpha, paintAlpha, paintAl pha, paintAlpha) :
1031 } 1036 color;
1032 1037
1033 BitmapTextBatch::Geometry geometry; 1038 BitmapTextBatch::Geometry geometry;
1034 geometry.fBlob.reset(SkRef(blob)); 1039 geometry.fBlob.reset(SkRef(blob));
1035 geometry.fRun = run; 1040 geometry.fRun = run;
1036 geometry.fSubRun = subRun; 1041 geometry.fSubRun = subRun;
1037 geometry.fColor = color; 1042 geometry.fColor = color;
1038 SkAutoTUnref<GrBatch> batch(BitmapTextBatch::Create(geometry, color, format, glyphCount, 1043 SkAutoTUnref<GrBatch> batch(BitmapTextBatch::Create(geometry, subRun Color, format,
1044 glyphCount,
1039 fContext->getBat chFontCache())); 1045 fContext->getBat chFontCache()));
1040 1046
1041 target->drawBatch(&pipelineBuilder, batch, &blob->fRuns[run].fVertex Bounds); 1047 target->drawBatch(&pipelineBuilder, batch, &blob->fRuns[run].fVertex Bounds);
1042 } 1048 }
1043 } 1049 }
1044 1050
1045 // Now flush big glyphs 1051 // Now flush big glyphs
1046 for (int i = 0; i < blob->fBigGlyphs.count(); i++) { 1052 for (int i = 0; i < blob->fBigGlyphs.count(); i++) {
1047 BitmapTextBlob::BigGlyph& bigGlyph = blob->fBigGlyphs[i]; 1053 BitmapTextBlob::BigGlyph& bigGlyph = blob->fBigGlyphs[i];
1048 SkMatrix translate; 1054 SkMatrix translate;
1049 translate.setTranslate(SkIntToScalar(bigGlyph.fVx), SkIntToScalar(bigGly ph.fVy)); 1055 translate.setTranslate(SkIntToScalar(bigGlyph.fVx), SkIntToScalar(bigGly ph.fVy));
1050 SkPath tmpPath(bigGlyph.fPath); 1056 SkPath tmpPath(bigGlyph.fPath);
1051 tmpPath.transform(translate); 1057 tmpPath.transform(translate);
1052 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); 1058 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle);
1053 fContext->drawPath(rt, clip, paint, SkMatrix::I(), tmpPath, strokeInfo); 1059 fContext->drawPath(rt, clip, paint, SkMatrix::I(), tmpPath, strokeInfo);
1054 } 1060 }
1055 } 1061 }
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698