SDL_ttf
SDL_ttf copied to clipboard
TTF_RenderUTF8_Blended very very slow in Android
It takes more than 1 second to run this function...

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);
}
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 ?
首先,这是模拟器。所以时间可能是错误的?
否则: 您可以做的是第一次渲染字符串,然后再渲染第二次。
第一次:它将渲染每个字形。然后缓存它们。然后渲染字符串。 第二次:使用字形缓存来渲染字符串。 比较时代。(如果两个字形共享相同的缓存槽,第二次也可能存在缓存未命中)。
更多问题: 大尺寸尺寸或款式可能会产生影响。 另外:使用亚像素+混合。 你用什么 ?
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?
Help
dont render the font every frame. Render the font when the text changes only on a texture. And render the texture every frame.
I render different texts that it cost more 5 seconds on HUAWEI p40... help~
Store SDL_Texture *
's in your oMsgVec
, update them only when the std::string
's change and render them using SDL_RenderCopy
.
Store
SDL_Texture *
's in youroMsgVec
, update them only when thestd::string
's change and render them usingSDL_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