libsdl-org / SDL_ttf

Support for TrueType (.ttf) font files with Simple Directmedia Layer.
zlib License
383 stars 128 forks source link

TTF_RenderUTF8_Blended very very slow in Android #193

Closed iBruCe07 closed 5 months ago

iBruCe07 commented 2 years ago

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);

}

1bsyl commented 2 years ago

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 ?

iBruCe07 commented 2 years ago

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

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

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

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

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 commented 2 years ago

Help

cjwijtmans commented 2 years ago

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

iBruCe07 commented 1 year ago

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

madebr commented 1 year ago

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

iBruCe07 commented 1 year ago

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

baidwwy commented 5 months ago

安卓的apk,zip是压缩的ttf,你应该把整个ttf读到内存,或者先从assets复制到 SDL_GetPrefPath In Android, the APK is a compressed file, and the TTF files are also compressed within it. You should either load the entire TTF file into memory or first copy it from the assets directory to SDL_GetPrefPath.