SDL_ttf icon indicating copy to clipboard operation
SDL_ttf copied to clipboard

TTF_RenderUTF8_Blended very very slow in Android

Open iBruCe07 opened this issue 2 years ago • 7 comments

It takes more than 1 second to run this function...

QQ20220404-200106@2x

SDL_Color oColor = {0xFF, 0xFF, 0xFF};

for (auto s : oMsgVec) { auto nStart = SDL_GetTicks64();

TTF_RenderUTF8_Blended(pFontHelper->m_pFont, s.c_str(), oColor);

auto nEnd = SDL_GetTicks64();

SDL_Log("%s: time = %d", s.c_str(), nEnd - nStart);

}

iBruCe07 avatar Apr 04 '22 12:04 iBruCe07

First, this is the emulator. so times are maybe wrong ?

otherwise: What you can do is to render a string a first time, then a second time.

first fime: it will render each glyph. then cache them. then render the string. second time: use the glyph cache, to render the string. compare the times. ( there can be cache misses in the second time also if two glyph share the same cache slot).

more issue: big size size, or style can have an impact. also: using subpixel + blending. What do you use ?

1bsyl avatar Apr 06 '22 11:04 1bsyl

首先,这是模拟器。所以时间可能是错误的?

否则: 您可以做的是第一次渲染字符串,然后再渲染第二次。

第一次:它将渲染每个字形。然后缓存它们。然后渲染字符串。 第二次:使用字形缓存来渲染字符串。 比较时代。(如果两个字形共享相同的缓存槽,第二次也可能存在缓存未命中)。

更多问题: 大尺寸尺寸或款式可能会产生影响。 另外:使用亚像素+混合。 你用什么 ?

Thank you for your help.

I'm run this app on huawei p40.

I don't understand your solution, can you give me more information?

iBruCe07 avatar Apr 27 '22 02:04 iBruCe07

Help

iBruCe07 avatar Jul 23 '22 20:07 iBruCe07

dont render the font every frame. Render the font when the text changes only on a texture. And render the texture every frame.

cjwijtmans avatar Aug 12 '22 13:08 cjwijtmans

I render different texts that it cost more 5 seconds on HUAWEI p40... help~

iBruCe07 avatar Oct 07 '23 08:10 iBruCe07

Store SDL_Texture *'s in your oMsgVec, update them only when the std::string's change and render them using SDL_RenderCopy.

madebr avatar Oct 07 '23 12:10 madebr

Store SDL_Texture *'s in your oMsgVec, update them only when the std::string's change and render them using SDL_RenderCopy.

I encountered a problem that it was run this function(TTF_RenderUTF8_Blended) cost more than 0.5 seconds to render one char(chinese) on HUAWEI p40 or virtual machine.I uploaded the test code,help~ android-project.zip

iBruCe07 avatar Oct 08 '23 04:10 iBruCe07