summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-13 14:25:14 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-13 14:25:14 +0200
commit1684318e5605ca0850dca0230bff1ba10bceb8bd (patch)
tree689e7aa315456baeca97bb30e0e9bb5a27d96167 /src/ui
parent60d5027a36067956a33be592ddb414c0c0a0ac73 (diff)
Text: Removed pending glyphs tracker
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/text.c55
-rw-r--r--src/ui/text.h2
-rw-r--r--src/ui/window.c1
3 files changed, 14 insertions, 44 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
206static iText text_; 205static iText text_;
@@ -438,7 +437,6 @@ static void initCache_Text_(iText *d) {
438static void deinitCache_Text_(iText *d) { 437static 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
444void init_Text(SDL_Renderer *render) { 442void 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
474void setOpacity_Text(float opacity) { 470void setOpacity_Text(float opacity) {
@@ -514,10 +510,6 @@ void resetFonts_Text(void) {
514 initFonts_Text_(d); 510 initFonts_Text_(d);
515} 511}
516 512
517size_t numPendingGlyphs_Text(void) {
518 return size_PtrSet(text_.pendingRaster);
519}
520
521iLocalDef iFont *font_Text_(enum iFontId id) { 513iLocalDef 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
708void rasterizeSomePendingGlyphs_Text(void) { 691static 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
718enum iRunMode { 705enum iRunMode {
@@ -727,20 +714,6 @@ enum iRunMode {
727 alwaysVariableWidthFlag_RunMode = iBit(12), 714 alwaysVariableWidthFlag_RunMode = iBit(12),
728}; 715};
729 716
730static 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
744static enum iFontId fontId_Text_(const iFont *font) { 717static 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;
diff --git a/src/ui/text.h b/src/ui/text.h
index c9f94307..897dfed0 100644
--- a/src/ui/text.h
+++ b/src/ui/text.h
@@ -171,8 +171,6 @@ void setContentFont_Text (enum iTextFont font);
171void setHeadingFont_Text (enum iTextFont font); 171void setHeadingFont_Text (enum iTextFont font);
172void setContentFontSize_Text (float fontSizeFactor); /* affects all except `default*` fonts */ 172void setContentFontSize_Text (float fontSizeFactor); /* affects all except `default*` fonts */
173void resetFonts_Text (void); 173void resetFonts_Text (void);
174size_t numPendingGlyphs_Text (void);
175void rasterizeSomePendingGlyphs_Text (void);
176 174
177int lineHeight_Text (int fontId); 175int lineHeight_Text (int fontId);
178iInt2 measure_Text (int fontId, const char *text); 176iInt2 measure_Text (int fontId, const char *text);
diff --git a/src/ui/window.c b/src/ui/window.c
index d8d0b3ea..29f240c2 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1862,7 +1862,6 @@ void draw_Window(iWindow *d) {
1862 } 1862 }
1863#endif 1863#endif
1864 SDL_RenderPresent(d->render); 1864 SDL_RenderPresent(d->render);
1865 rasterizeSomePendingGlyphs_Text();
1866} 1865}
1867 1866
1868void resize_Window(iWindow *d, int w, int h) { 1867void resize_Window(iWindow *d, int w, int h) {