1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

SDL2: Support highdpi (#14703)

and handle DPI changes at runtime
This commit is contained in:
grorp 2024-06-16 17:49:42 +02:00 committed by GitHub
parent 7a64527db5
commit a9cca5e76c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 84 additions and 47 deletions

View file

@ -462,18 +462,14 @@ const VideoDriverInfo &RenderingEngine::getVideoDriverInfo(irr::video::E_DRIVER_
float RenderingEngine::getDisplayDensity()
{
float user_factor = g_settings->getFloat("display_density_factor", 0.5f, 5.0f);
#ifndef __ANDROID__
static float cached_display_density = [&] {
float dpi = get_raw_device()->getDisplayDensity();
// fall back to manually specified dpi
if (dpi == 0.0f)
dpi = g_settings->getFloat("screen_dpi");
return dpi / 96.0f;
}();
return std::max(cached_display_density * g_settings->getFloat("display_density_factor"), 0.5f);
float dpi = get_raw_device()->getDisplayDensity();
if (dpi == 0.0f)
dpi = 96.0f;
return std::max(dpi / 96.0f * user_factor, 0.5f);
#else // __ANDROID__
return porting::getDisplayDensity();
return porting::getDisplayDensity() * user_factor;
#endif // __ANDROID__
}