diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-13 14:25:14 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-13 14:25:14 +0200 |
commit | 1684318e5605ca0850dca0230bff1ba10bceb8bd (patch) | |
tree | 689e7aa315456baeca97bb30e0e9bb5a27d96167 /src/ui/text.c | |
parent | 60d5027a36067956a33be592ddb414c0c0a0ac73 (diff) |
Text: Removed pending glyphs tracker
Diffstat (limited to 'src/ui/text.c')
-rw-r--r-- | src/ui/text.c | 55 |
1 files changed, 14 insertions, 41 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index a803da97..36e98e11 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -200,7 +200,6 @@ struct Impl_Text { | |||
200 | iArray cacheRows; | 200 | iArray cacheRows; |
201 | SDL_Palette * grayscale; | 201 | SDL_Palette * grayscale; |
202 | iRegExp * ansiEscape; | 202 | iRegExp * ansiEscape; |
203 | iPtrSet * pendingRaster; /* glyphs */ | ||
204 | }; | 203 | }; |
205 | 204 | ||
206 | static iText text_; | 205 | static iText text_; |
@@ -438,7 +437,6 @@ static void initCache_Text_(iText *d) { | |||
438 | static void deinitCache_Text_(iText *d) { | 437 | static void deinitCache_Text_(iText *d) { |
439 | deinit_Array(&d->cacheRows); | 438 | deinit_Array(&d->cacheRows); |
440 | SDL_DestroyTexture(d->cache); | 439 | SDL_DestroyTexture(d->cache); |
441 | clear_PtrSet(text_.pendingRaster); | ||
442 | } | 440 | } |
443 | 441 | ||
444 | void init_Text(SDL_Renderer *render) { | 442 | void init_Text(SDL_Renderer *render) { |
@@ -456,7 +454,6 @@ void init_Text(SDL_Renderer *render) { | |||
456 | d->grayscale = SDL_AllocPalette(256); | 454 | d->grayscale = SDL_AllocPalette(256); |
457 | SDL_SetPaletteColors(d->grayscale, colors, 0, 256); | 455 | SDL_SetPaletteColors(d->grayscale, colors, 0, 256); |
458 | } | 456 | } |
459 | d->pendingRaster = new_PtrSet(); | ||
460 | initCache_Text_(d); | 457 | initCache_Text_(d); |
461 | initFonts_Text_(d); | 458 | initFonts_Text_(d); |
462 | } | 459 | } |
@@ -468,7 +465,6 @@ void deinit_Text(void) { | |||
468 | deinitCache_Text_(d); | 465 | deinitCache_Text_(d); |
469 | d->render = NULL; | 466 | d->render = NULL; |
470 | iRelease(d->ansiEscape); | 467 | iRelease(d->ansiEscape); |
471 | delete_PtrSet(d->pendingRaster); | ||
472 | } | 468 | } |
473 | 469 | ||
474 | void setOpacity_Text(float opacity) { | 470 | void setOpacity_Text(float opacity) { |
@@ -514,10 +510,6 @@ void resetFonts_Text(void) { | |||
514 | initFonts_Text_(d); | 510 | initFonts_Text_(d); |
515 | } | 511 | } |
516 | 512 | ||
517 | size_t numPendingGlyphs_Text(void) { | ||
518 | return size_PtrSet(text_.pendingRaster); | ||
519 | } | ||
520 | |||
521 | iLocalDef iFont *font_Text_(enum iFontId id) { | 513 | iLocalDef iFont *font_Text_(enum iFontId id) { |
522 | return &text_.fonts[id & mask_FontId]; | 514 | return &text_.fonts[id & mask_FontId]; |
523 | } | 515 | } |
@@ -656,18 +648,10 @@ static void doRaster_Font_(const iFont *font, iGlyph *glyph) { | |||
656 | SDL_Texture *oldTarget = SDL_GetRenderTarget(text_.render); | 648 | SDL_Texture *oldTarget = SDL_GetRenderTarget(text_.render); |
657 | SDL_SetRenderTarget(text_.render, text_.cache); | 649 | SDL_SetRenderTarget(text_.render, text_.cache); |
658 | if (!isRasterized_Glyph_(glyph, 0)) { | 650 | if (!isRasterized_Glyph_(glyph, 0)) { |
659 | if (cache_Font_(font, glyph, 0)) { | 651 | cache_Font_(font, glyph, 0); |
660 | if (isFullyRasterized_Glyph_(glyph)) { | ||
661 | remove_PtrSet(text_.pendingRaster, glyph); | ||
662 | } | ||
663 | } | ||
664 | } | 652 | } |
665 | if (!isRasterized_Glyph_(glyph, 1)) { | 653 | if (!isRasterized_Glyph_(glyph, 1)) { |
666 | if (cache_Font_(font, glyph, 1)) { /* half-pixel offset */ | 654 | cache_Font_(font, glyph, 1); /* half-pixel offset */ |
667 | if (isFullyRasterized_Glyph_(glyph)) { | ||
668 | remove_PtrSet(text_.pendingRaster, glyph); | ||
669 | } | ||
670 | } | ||
671 | } | 655 | } |
672 | SDL_SetRenderTarget(text_.render, oldTarget); | 656 | SDL_SetRenderTarget(text_.render, oldTarget); |
673 | } | 657 | } |
@@ -697,7 +681,6 @@ static const iGlyph *glyph_Font_(iFont *d, iChar ch) { | |||
697 | allocate_Font_(font, glyph, 0); | 681 | allocate_Font_(font, glyph, 0); |
698 | allocate_Font_(font, glyph, 1); | 682 | allocate_Font_(font, glyph, 1); |
699 | insert_Hash(&font->glyphs, &glyph->node); | 683 | insert_Hash(&font->glyphs, &glyph->node); |
700 | insert_PtrSet(text_.pendingRaster, glyph); | ||
701 | } | 684 | } |
702 | if (enableRaster_Text_ && !isFullyRasterized_Glyph_(glyph)) { | 685 | if (enableRaster_Text_ && !isFullyRasterized_Glyph_(glyph)) { |
703 | doRaster_Font_(font, glyph); | 686 | doRaster_Font_(font, glyph); |
@@ -705,14 +688,18 @@ static const iGlyph *glyph_Font_(iFont *d, iChar ch) { | |||
705 | return glyph; | 688 | return glyph; |
706 | } | 689 | } |
707 | 690 | ||
708 | void rasterizeSomePendingGlyphs_Text(void) { | 691 | static iChar nextChar_(const char **chPos, const char *end) { |
709 | size_t count = 5; | 692 | if (*chPos == end) { |
710 | iForEach(PtrSet, i, text_.pendingRaster) { | 693 | return 0; |
711 | iGlyph *glyph = *i.value; | 694 | } |
712 | remove_PtrSet(text_.pendingRaster, glyph); | 695 | iChar ch; |
713 | doRaster_Font_(glyph->font, glyph); | 696 | int len = decodeBytes_MultibyteChar(*chPos, end - *chPos, &ch); |
714 | if (!count--) break; | 697 | if (len <= 0) { |
698 | (*chPos)++; /* skip it */ | ||
699 | return 0; | ||
715 | } | 700 | } |
701 | (*chPos) += len; | ||
702 | return ch; | ||
716 | } | 703 | } |
717 | 704 | ||
718 | enum iRunMode { | 705 | enum iRunMode { |
@@ -727,20 +714,6 @@ enum iRunMode { | |||
727 | alwaysVariableWidthFlag_RunMode = iBit(12), | 714 | alwaysVariableWidthFlag_RunMode = iBit(12), |
728 | }; | 715 | }; |
729 | 716 | ||
730 | static iChar nextChar_(const char **chPos, const char *end) { | ||
731 | if (*chPos == end) { | ||
732 | return 0; | ||
733 | } | ||
734 | iChar ch; | ||
735 | int len = decodeBytes_MultibyteChar(*chPos, end - *chPos, &ch); | ||
736 | if (len <= 0) { | ||
737 | (*chPos)++; /* skip it */ | ||
738 | return 0; | ||
739 | } | ||
740 | (*chPos) += len; | ||
741 | return ch; | ||
742 | } | ||
743 | |||
744 | static enum iFontId fontId_Text_(const iFont *font) { | 717 | static enum iFontId fontId_Text_(const iFont *font) { |
745 | return (enum iFontId) (font - text_.fonts); | 718 | return (enum iFontId) (font - text_.fonts); |
746 | } | 719 | } |
@@ -949,7 +922,7 @@ static iRect run_Font_(iFont *d, const iRunArgs *args) { | |||
949 | const iBool useMonoAdvance = | 922 | const iBool useMonoAdvance = |
950 | monoAdvance > 0 && !isJapanese_FontId(fontId_Text_(glyph->font)); | 923 | monoAdvance > 0 && !isJapanese_FontId(fontId_Text_(glyph->font)); |
951 | const float advance = (useMonoAdvance ? monoAdvance : glyph->advance); | 924 | const float advance = (useMonoAdvance ? monoAdvance : glyph->advance); |
952 | if (!isMeasuring_(mode)) { | 925 | if (!isMeasuring_(mode) && ch != 0x20 /* don't bother rendering spaces */) { |
953 | if (useMonoAdvance && dst.w > advance && glyph->font != d && !isEmoji) { | 926 | if (useMonoAdvance && dst.w > advance && glyph->font != d && !isEmoji) { |
954 | /* Glyphs from a different font may need recentering to look better. */ | 927 | /* Glyphs from a different font may need recentering to look better. */ |
955 | dst.x -= (dst.w - advance) / 2; | 928 | dst.x -= (dst.w - advance) / 2; |