bi: Re-add screen dpi report

This was a casualty of 575286cb86
even though this particular use case is purely diagnostic for
devs reference when handling bug reports.
This commit is contained in:
Iris Morelle 2023-01-20 23:06:51 -03:00 committed by Steve Cotton
parent daf126c75d
commit 20e8402ae0
3 changed files with 40 additions and 0 deletions

View file

@ -521,6 +521,13 @@ inline std::string geometry_to_string(point p)
return std::to_string(p.x) + 'x' + std::to_string(p.y);
}
template<typename coordinateType>
inline std::string geometry_to_string(coordinateType horizontal, coordinateType vertical)
{
// Use a stream in order to control significant digits in non-integers
return formatter() << std::fixed << std::setprecision(2) << horizontal << 'x' << vertical;
}
std::string format_sdl_driver_list(std::vector<std::string> drivers, const std::string& current_driver)
{
bool found_current_driver = false;
@ -562,11 +569,19 @@ list_formatter video_settings_report_internal(const std::string& heading = "")
const auto& current_driver = video::current_driver();
auto drivers = video::enumerate_drivers();
const auto& dpi = video::get_dpi();
std::string dpi_report;
dpi_report = dpi.first == 0.0f || dpi.second == 0.0f ?
"<unknown>" :
geometry_to_string(dpi.first, dpi.second);
fmt.insert("SDL video drivers", format_sdl_driver_list(drivers, current_driver));
fmt.insert("Window size", geometry_to_string(video::current_resolution()));
fmt.insert("Game canvas size", geometry_to_string(video::game_canvas_size()));
fmt.insert("Final render target size", geometry_to_string(video::output_size()));
fmt.insert("Screen refresh rate", std::to_string(video::current_refresh_rate()));
fmt.insert("Screen dpi", dpi_report);
const auto& renderer_report = video::renderer_report();

View file

@ -828,6 +828,26 @@ void update_buffers(bool autoupdate)
}
}
std::pair<float, float> get_dpi()
{
float hdpi = 0.0f, vdpi = 0.0f;
if(window && SDL_GetDisplayDPI(window->get_display_index(), nullptr, &hdpi, &vdpi) == 0) {
#ifdef TARGET_OS_OSX
// SDL 2.0.12 changes SDL_GetDisplayDPI. Function now returns DPI
// multiplied by screen's scale factor. This part of code reverts
// this multiplication.
//
// For more info see issue: https://github.com/wesnoth/wesnoth/issues/5019
if(sdl::get_version() >= version_info{2, 0, 12}) {
float scale_factor = desktop::apple::get_scale_factor(window->get_display_index());
hdpi /= scale_factor;
vdpi /= scale_factor;
}
#endif
}
return { hdpi, vdpi };
}
std::vector<std::pair<std::string, std::string>> renderer_report()
{
std::vector<std::pair<std::string, std::string>> res;

View file

@ -332,6 +332,11 @@ private:
*/
std::vector<std::pair<std::string, std::string>> renderer_report();
/**
* Retrieves the current game screen DPI for the @a build_info API.
*/
std::pair<float, float> get_dpi();
/**************************/
/* Implementation details */