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

Side by Side Diff: src/gpu/text/GrStencilAndCoverTextContext.cpp

Issue 2335493005: Use sk_sp text blob APIs (Closed)
Patch Set: SK_SUPPORT_LEGACY_TEXTBLOB_BUILDER Created 4 years, 3 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/text/GrStencilAndCoverTextContext.h ('k') | src/utils/SkLua.cpp » ('j') | 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 2014 Google Inc. 2 * Copyright 2014 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 "GrStencilAndCoverTextContext.h" 8 #include "GrStencilAndCoverTextContext.h"
9 #include "GrAtlasTextContext.h" 9 #include "GrAtlasTextContext.h"
10 #include "GrContext.h" 10 #include "GrContext.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 class GrStencilAndCoverTextContext::FallbackBlobBuilder { 337 class GrStencilAndCoverTextContext::FallbackBlobBuilder {
338 public: 338 public:
339 FallbackBlobBuilder() : fBuffIdx(0), fCount(0) {} 339 FallbackBlobBuilder() : fBuffIdx(0), fCount(0) {}
340 340
341 bool isInitialized() const { return fBuilder != nullptr; } 341 bool isInitialized() const { return fBuilder != nullptr; }
342 342
343 void init(const SkPaint& font, SkScalar textRatio); 343 void init(const SkPaint& font, SkScalar textRatio);
344 344
345 void appendGlyph(uint16_t glyphId, const SkPoint& pos); 345 void appendGlyph(uint16_t glyphId, const SkPoint& pos);
346 346
347 const SkTextBlob* buildIfNeeded(int* count); 347 sk_sp<SkTextBlob> makeIfNeeded(int* count);
348 348
349 private: 349 private:
350 enum { kWriteBufferSize = 1024 }; 350 enum { kWriteBufferSize = 1024 };
351 351
352 void flush(); 352 void flush();
353 353
354 SkAutoTDelete<SkTextBlobBuilder> fBuilder; 354 SkAutoTDelete<SkTextBlobBuilder> fBuilder;
355 SkPaint fFont; 355 SkPaint fFont;
356 int fBuffIdx; 356 int fBuffIdx;
357 int fCount; 357 int fCount;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 const SkGlyph& glyph = glyphCacheProc(glyphCache, &text); 514 const SkGlyph& glyph = glyphCacheProc(glyphCache, &text);
515 x += autokern.adjust(glyph) * fTextRatio; 515 x += autokern.adjust(glyph) * fTextRatio;
516 if (glyph.fWidth) { 516 if (glyph.fWidth) {
517 this->appendGlyph(glyph, SkPoint::Make(x, y), &fallback); 517 this->appendGlyph(glyph, SkPoint::Make(x, y), &fallback);
518 } 518 }
519 519
520 x += SkFloatToScalar(glyph.fAdvanceX) * fTextRatio; 520 x += SkFloatToScalar(glyph.fAdvanceX) * fTextRatio;
521 y += SkFloatToScalar(glyph.fAdvanceY) * fTextRatio; 521 y += SkFloatToScalar(glyph.fAdvanceY) * fTextRatio;
522 } 522 }
523 523
524 fFallbackTextBlob.reset(fallback.buildIfNeeded(&fFallbackGlyphCount)); 524 fFallbackTextBlob = fallback.makeIfNeeded(&fFallbackGlyphCount);
525 } 525 }
526 526
527 void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t byteLength, 527 void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t byteLength,
528 const SkScalar pos[], int scalarsPerPosition, 528 const SkScalar pos[], int scalarsPerPosition,
529 const SkPoint& offset) { 529 const SkPoint& offset) {
530 SkASSERT(byteLength == 0 || text != nullptr); 530 SkASSERT(byteLength == 0 || text != nullptr);
531 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 531 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
532 532
533 SkGlyphCache* glyphCache = this->getGlyphCache(); 533 SkGlyphCache* glyphCache = this->getGlyphCache();
534 SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(fFont.ge tTextEncoding(), 534 SkPaint::GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(fFont.ge tTextEncoding(),
(...skipping 15 matching lines...) Expand all
550 SkPoint tmsLoc; 550 SkPoint tmsLoc;
551 tmsProc(pos, &tmsLoc); 551 tmsProc(pos, &tmsLoc);
552 SkPoint loc; 552 SkPoint loc;
553 alignProc(tmsLoc, glyph, &loc); 553 alignProc(tmsLoc, glyph, &loc);
554 554
555 this->appendGlyph(glyph, loc, &fallback); 555 this->appendGlyph(glyph, loc, &fallback);
556 } 556 }
557 pos += scalarsPerPosition; 557 pos += scalarsPerPosition;
558 } 558 }
559 559
560 fFallbackTextBlob.reset(fallback.buildIfNeeded(&fFallbackGlyphCount)); 560 fFallbackTextBlob = fallback.makeIfNeeded(&fFallbackGlyphCount);
561 } 561 }
562 562
563 GrPathRange* GrStencilAndCoverTextContext::TextRun::createGlyphs(GrContext* ctx) const { 563 GrPathRange* GrStencilAndCoverTextContext::TextRun::createGlyphs(GrContext* ctx) const {
564 GrPathRange* glyphs = static_cast<GrPathRange*>( 564 GrPathRange* glyphs = static_cast<GrPathRange*>(
565 ctx->resourceProvider()->findAndRefResourceByUniqueKey(fGlyphPathsKe y)); 565 ctx->resourceProvider()->findAndRefResourceByUniqueKey(fGlyphPathsKe y));
566 if (nullptr == glyphs) { 566 if (nullptr == glyphs) {
567 if (fUsingRawGlyphPaths) { 567 if (fUsingRawGlyphPaths) {
568 SkScalerContextEffects noeffects; 568 SkScalerContextEffects noeffects;
569 glyphs = ctx->resourceProvider()->createGlyphs(fFont.getTypeface(), noeffects, 569 glyphs = ctx->resourceProvider()->createGlyphs(fFont.getTypeface(), noeffects,
570 nullptr, fStyle); 570 nullptr, fStyle);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 647 }
648 648
649 if (fFallbackTextBlob) { 649 if (fFallbackTextBlob) {
650 SkPaint fallbackSkPaint(originalSkPaint); 650 SkPaint fallbackSkPaint(originalSkPaint);
651 fStyle.strokeRec().applyToPaint(&fallbackSkPaint); 651 fStyle.strokeRec().applyToPaint(&fallbackSkPaint);
652 if (!fStyle.isSimpleFill()) { 652 if (!fStyle.isSimpleFill()) {
653 fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fText Ratio); 653 fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fText Ratio);
654 } 654 }
655 655
656 fallbackTextContext->drawTextBlob(ctx, drawContext, clip, fallbackSkPain t, viewMatrix, 656 fallbackTextContext->drawTextBlob(ctx, drawContext, clip, fallbackSkPain t, viewMatrix,
657 props, fFallbackTextBlob, x, y, nullpt r, clipBounds); 657 props, fFallbackTextBlob.get(), x, y, nullptr,
658 clipBounds);
658 } 659 }
659 } 660 }
660 661
661 SkGlyphCache* GrStencilAndCoverTextContext::TextRun::getGlyphCache() const { 662 SkGlyphCache* GrStencilAndCoverTextContext::TextRun::getGlyphCache() const {
662 if (!fDetachedGlyphCache) { 663 if (!fDetachedGlyphCache) {
663 fDetachedGlyphCache = fFont.detachCache(nullptr, SkPaint::kNone_ScalerCo ntextFlags, 664 fDetachedGlyphCache = fFont.detachCache(nullptr, SkPaint::kNone_ScalerCo ntextFlags,
664 nullptr); 665 nullptr);
665 } 666 }
666 return fDetachedGlyphCache; 667 return fDetachedGlyphCache;
667 } 668 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 if (!fBuffIdx) { 722 if (!fBuffIdx) {
722 return; 723 return;
723 } 724 }
724 // This will automatically merge with previous runs since we use the same fo nt. 725 // This will automatically merge with previous runs since we use the same fo nt.
725 const SkTextBlobBuilder::RunBuffer& buff = fBuilder->allocRunPos(fFont, fBuf fIdx); 726 const SkTextBlobBuilder::RunBuffer& buff = fBuilder->allocRunPos(fFont, fBuf fIdx);
726 memcpy(buff.glyphs, fGlyphIds, fBuffIdx * sizeof(uint16_t)); 727 memcpy(buff.glyphs, fGlyphIds, fBuffIdx * sizeof(uint16_t));
727 memcpy(buff.pos, fPositions[0].asScalars(), fBuffIdx * 2 * sizeof(SkScalar)) ; 728 memcpy(buff.pos, fPositions[0].asScalars(), fBuffIdx * 2 * sizeof(SkScalar)) ;
728 fBuffIdx = 0; 729 fBuffIdx = 0;
729 } 730 }
730 731
731 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed ed(int *count) { 732 sk_sp<SkTextBlob> GrStencilAndCoverTextContext::FallbackBlobBuilder::makeIfNeede d(int *count) {
732 *count = fCount; 733 *count = fCount;
733 if (fCount) { 734 if (fCount) {
734 this->flush(); 735 this->flush();
735 return fBuilder->build(); 736 return fBuilder->make();
736 } 737 }
737 return nullptr; 738 return nullptr;
738 } 739 }
OLDNEW
« no previous file with comments | « src/gpu/text/GrStencilAndCoverTextContext.h ('k') | src/utils/SkLua.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698