Qt/macOS: enable HiDPI ( retina display ) support

This commit is contained in:
李通洲 2020-01-05 15:46:27 +08:00
parent 97de0ac6da
commit 0a2aa2c3af
No known key found for this signature in database
GPG Key ID: 185E60A519A7E290
4 changed files with 42 additions and 21 deletions

View File

@ -150,7 +150,12 @@ static bool IsWindowSmall(int pixelWidth, int pixelHeight) {
// TODO: Feels like this belongs elsewhere.
bool UpdateScreenScale(int width, int height) {
bool smallWindow;
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
#if defined(USING_QT_UI)
g_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_DPI);
float g_logical_dpi = System_GetPropertyFloat(SYSPROP_DISPLAY_LOGICAL_DPI);
g_dpi_scale_x = g_logical_dpi / g_dpi;
g_dpi_scale_y = g_logical_dpi / g_dpi;
#elif PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
g_dpi = (float)System_GetPropertyInt(SYSPROP_DISPLAY_DPI);
g_dpi_scale_x = 96.0f / g_dpi;
g_dpi_scale_y = 96.0f / g_dpi;

View File

@ -159,11 +159,24 @@ int System_GetPropertyInt(SystemProperty prop) {
#else
return DEVICE_TYPE_DESKTOP;
#endif
case SYSPROP_DISPLAY_COUNT:
return QApplication::screens().size();
default:
return -1;
}
}
int System_GetPropertyFloat(SystemProperty prop) {
switch (prop) {
case SYSPROP_DISPLAY_LOGICAL_DPI:
return QApplication::primaryScreen()->logicalDotsPerInch();
case SYSPROP_DISPLAY_DPI:
return QApplication::primaryScreen()->physicalDotsPerInch();
default:
return System_GetPropertyInt(prop);
}
}
bool System_GetPropertyBool(SystemProperty prop) {
switch (prop) {
case SYSPROP_HAS_BACK_BUTTON:
@ -229,16 +242,6 @@ void LaunchBrowser(const char *url)
QDesktopServices::openUrl(QUrl(url));
}
float CalculateDPIScale()
{
// Sane default rather than check DPI
#if defined(USING_GLES2)
return 1.2f;
#else
return 1.0f;
#endif
}
static int mainInternal(QApplication &a) {
#ifdef MOBILE_DEVICE
emugl = new MainUI();
@ -628,19 +631,21 @@ int main(int argc, char *argv[])
QGLFormat::setDefaultFormat(format);
QApplication a(argc, argv);
QSize res = QApplication::desktop()->screenGeometry().size();
QScreen* screen = a.primaryScreen();
QSizeF res = screen->physicalSize();
if (res.width() < res.height())
res.transpose();
pixel_xres = res.width();
pixel_yres = res.height();
g_dpi_scale_x = CalculateDPIScale();
g_dpi_scale_y = CalculateDPIScale();
g_dpi_scale_x = screen->logicalDotsPerInchX() / screen->physicalDotsPerInchX();
g_dpi_scale_y = screen->logicalDotsPerInchY() / screen->physicalDotsPerInchY();
g_dpi_scale_real_x = g_dpi_scale_x;
g_dpi_scale_real_y = g_dpi_scale_y;
dp_xres = (int)(pixel_xres * g_dpi_scale_x);
dp_yres = (int)(pixel_yres * g_dpi_scale_y);
refreshRate = (int)(a.primaryScreen()->refreshRate() * 1000);
refreshRate = (int)(screen->refreshRate() * 1000);
std::string savegame_dir = ".";
std::string external_dir = ".";
@ -669,4 +674,3 @@ int main(int argc, char *argv[])
glslang::FinalizeProcess();
return ret;
}

View File

@ -301,13 +301,16 @@ void MainWindow::raiseTopMost()
void MainWindow::SetFullScreen(bool fullscreen) {
if (fullscreen) {
#if !PPSSPP_PLATFORM(MAC)
menuBar()->hide();
emugl->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
// TODO: Shouldn't this be physicalSize()?
emugl->resizeGL(emugl->size().width(), emugl->size().height());
// TODO: Won't showFullScreen do this for us?
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
#endif
showFullScreen();
InitPadLayout(dp_xres, dp_yres);
@ -315,8 +318,10 @@ void MainWindow::SetFullScreen(bool fullscreen) {
if (GetUIState() == UISTATE_INGAME && !g_Config.bShowTouchControls)
QApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
} else {
#if !PPSSPP_PLATFORM(MAC)
menuBar()->show();
updateMenus();
#endif
showNormal();
SetWindowScale(-1);
@ -394,9 +399,14 @@ void MainWindow::SetWindowScale(int zoom) {
g_Config.iWindowWidth = width;
g_Config.iWindowHeight = height;
#if !PPSSPP_PLATFORM(MAC)
emugl->setFixedSize(g_Config.iWindowWidth, g_Config.iWindowHeight);
// TODO: Shouldn't this be scaled size?
emugl->resizeGL(g_Config.iWindowWidth, g_Config.iWindowHeight);
setFixedSize(sizeHint());
#else
resize(g_Config.iWindowWidth, g_Config.iWindowHeight);
#endif
}
void MainWindow::SetGameTitle(QString text)

View File

@ -149,6 +149,7 @@ enum SystemProperty {
SYSPROP_DISPLAY_XRES,
SYSPROP_DISPLAY_YRES,
SYSPROP_DISPLAY_REFRESH_RATE, // returns 1000*the refresh rate in Hz as it can be non-integer
SYSPROP_DISPLAY_LOGICAL_DPI,
SYSPROP_DISPLAY_DPI,
SYSPROP_DISPLAY_COUNT,
SYSPROP_MOGA_VERSION,
@ -173,6 +174,7 @@ enum SystemProperty {
std::string System_GetProperty(SystemProperty prop);
int System_GetPropertyInt(SystemProperty prop);
int System_GetPropertyFloat(SystemProperty prop);
bool System_GetPropertyBool(SystemProperty prop);
std::vector<std::string> __cameraGetDeviceList();