diff options
Diffstat (limited to 'src/ui/text.c')
-rw-r--r-- | src/ui/text.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/ui/text.c b/src/ui/text.c index d3b8df37..b08bdc60 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -53,6 +53,7 @@ int enableHalfPixelGlyphs_Text = iTrue; /* debug setting */ | |||
53 | int enableKerning_Text = iTrue; /* looking up kern pairs is slow */ | 53 | int enableKerning_Text = iTrue; /* looking up kern pairs is slow */ |
54 | 54 | ||
55 | static iBool enableRaster_Text_ = iTrue; | 55 | static iBool enableRaster_Text_ = iTrue; |
56 | static int numPendingRasterization_Text_ = 0; | ||
56 | 57 | ||
57 | enum iGlyphFlag { | 58 | enum iGlyphFlag { |
58 | rasterized0_GlyphFlag = iBit(1), /* zero offset */ | 59 | rasterized0_GlyphFlag = iBit(1), /* zero offset */ |
@@ -423,6 +424,7 @@ static void initCache_Text_(iText *d) { | |||
423 | d->cacheSize.x, | 424 | d->cacheSize.x, |
424 | d->cacheSize.y); | 425 | d->cacheSize.y); |
425 | SDL_SetTextureBlendMode(d->cache, SDL_BLENDMODE_BLEND); | 426 | SDL_SetTextureBlendMode(d->cache, SDL_BLENDMODE_BLEND); |
427 | numPendingRasterization_Text_ = 0; | ||
426 | } | 428 | } |
427 | 429 | ||
428 | static void deinitCache_Text_(iText *d) { | 430 | static void deinitCache_Text_(iText *d) { |
@@ -501,6 +503,10 @@ void resetFonts_Text(void) { | |||
501 | initFonts_Text_(d); | 503 | initFonts_Text_(d); |
502 | } | 504 | } |
503 | 505 | ||
506 | int numPendingGlyphs_Text(void) { | ||
507 | return numPendingRasterization_Text_; | ||
508 | } | ||
509 | |||
504 | iLocalDef iFont *font_Text_(enum iFontId id) { | 510 | iLocalDef iFont *font_Text_(enum iFontId id) { |
505 | return &text_.fonts[id & mask_FontId]; | 511 | return &text_.fonts[id & mask_FontId]; |
506 | } | 512 | } |
@@ -569,7 +575,7 @@ static void allocate_Font_(iFont *d, iGlyph *glyph, int hoff) { | |||
569 | } | 575 | } |
570 | } | 576 | } |
571 | 577 | ||
572 | static void cache_Font_(iFont *d, iGlyph *glyph, int hoff) { | 578 | static iBool cache_Font_(iFont *d, iGlyph *glyph, int hoff) { |
573 | iText * txt = &text_; | 579 | iText * txt = &text_; |
574 | SDL_Renderer *render = txt->render; | 580 | SDL_Renderer *render = txt->render; |
575 | SDL_Texture * tex = NULL; | 581 | SDL_Texture * tex = NULL; |
@@ -590,6 +596,7 @@ static void cache_Font_(iFont *d, iGlyph *glyph, int hoff) { | |||
590 | if (surface) { | 596 | if (surface) { |
591 | SDL_FreeSurface(surface); | 597 | SDL_FreeSurface(surface); |
592 | } | 598 | } |
599 | return isRasterized_Glyph_(glyph, hoff); | ||
593 | } | 600 | } |
594 | 601 | ||
595 | iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { | 602 | iLocalDef iFont *characterFont_Font_(iFont *d, iChar ch, uint32_t *glyphIndex) { |
@@ -659,15 +666,22 @@ static const iGlyph *glyph_Font_(iFont *d, iChar ch) { | |||
659 | allocate_Font_(font, glyph, 0); | 666 | allocate_Font_(font, glyph, 0); |
660 | allocate_Font_(font, glyph, 1); | 667 | allocate_Font_(font, glyph, 1); |
661 | insert_Hash(&font->glyphs, &glyph->node); | 668 | insert_Hash(&font->glyphs, &glyph->node); |
669 | numPendingRasterization_Text_ += 2; | ||
662 | } | 670 | } |
663 | if (enableRaster_Text_ && !isFullyRasterized_Glyph_(glyph)) { | 671 | if (enableRaster_Text_ && !isFullyRasterized_Glyph_(glyph)) { |
664 | SDL_Texture *oldTarget = SDL_GetRenderTarget(text_.render); | 672 | SDL_Texture *oldTarget = SDL_GetRenderTarget(text_.render); |
665 | SDL_SetRenderTarget(text_.render, text_.cache); | 673 | SDL_SetRenderTarget(text_.render, text_.cache); |
666 | if (!isRasterized_Glyph_(glyph, 0)) { | 674 | if (!isRasterized_Glyph_(glyph, 0)) { |
667 | cache_Font_(font, glyph, 0); | 675 | if (cache_Font_(font, glyph, 0)) { |
676 | numPendingRasterization_Text_--; | ||
677 | iAssert(numPendingRasterization_Text_ >= 0); | ||
678 | } | ||
668 | } | 679 | } |
669 | if (!isRasterized_Glyph_(glyph, 1)) { | 680 | if (!isRasterized_Glyph_(glyph, 1)) { |
670 | cache_Font_(font, glyph, 1); /* half-pixel offset */ | 681 | if (cache_Font_(font, glyph, 1)) { /* half-pixel offset */ |
682 | numPendingRasterization_Text_--; | ||
683 | iAssert(numPendingRasterization_Text_ >= 0); | ||
684 | } | ||
671 | } | 685 | } |
672 | SDL_SetRenderTarget(text_.render, oldTarget); | 686 | SDL_SetRenderTarget(text_.render, oldTarget); |
673 | } | 687 | } |