From c605408367c3363c6296e72c7edff502f86c1168 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Fri, 25 Feb 2022 14:36:27 +0100 Subject: [PATCH] MacOS: ensure 1:1 rendering on HiDPI screens (#23860) --- selfdrive/ui/installer/installer.cc | 2 +- selfdrive/ui/main.cc | 2 +- selfdrive/ui/qt/setup/updater.cc | 2 +- selfdrive/ui/qt/spinner.cc | 2 +- selfdrive/ui/qt/text.cc | 2 +- selfdrive/ui/qt/util.cc | 11 ++++++++++- selfdrive/ui/qt/util.h | 2 +- selfdrive/ui/watch3.cc | 2 +- 8 files changed, 17 insertions(+), 8 deletions(-) diff --git a/selfdrive/ui/installer/installer.cc b/selfdrive/ui/installer/installer.cc index 6ee6e99e097e9f..5366a0eac685cd 100644 --- a/selfdrive/ui/installer/installer.cc +++ b/selfdrive/ui/installer/installer.cc @@ -221,7 +221,7 @@ void Installer::cloneFinished(int exitCode, QProcess::ExitStatus exitStatus) { } int main(int argc, char *argv[]) { - initApp(); + initApp(argc, argv); QApplication a(argc, argv); Installer installer; setMainWindow(&installer); diff --git a/selfdrive/ui/main.cc b/selfdrive/ui/main.cc index 3d2411b9c67c0c..8477bc8966d4f5 100644 --- a/selfdrive/ui/main.cc +++ b/selfdrive/ui/main.cc @@ -12,7 +12,7 @@ int main(int argc, char *argv[]) { setpriority(PRIO_PROCESS, 0, -20); qInstallMessageHandler(swagLogMessageHandler); - initApp(); + initApp(argc, argv); if (Hardware::EON()) { QSslConfiguration ssl = QSslConfiguration::defaultConfiguration(); diff --git a/selfdrive/ui/qt/setup/updater.cc b/selfdrive/ui/qt/setup/updater.cc index dfa63fca117caf..6345d80db80b39 100644 --- a/selfdrive/ui/qt/setup/updater.cc +++ b/selfdrive/ui/qt/setup/updater.cc @@ -190,7 +190,7 @@ bool Updater::eventFilter(QObject *obj, QEvent *event) { } int main(int argc, char *argv[]) { - initApp(); + initApp(argc, argv); QApplication a(argc, argv); Updater updater(argv[1], argv[2]); setMainWindow(&updater); diff --git a/selfdrive/ui/qt/spinner.cc b/selfdrive/ui/qt/spinner.cc index b9868f603585ab..e0b263227b6da3 100644 --- a/selfdrive/ui/qt/spinner.cc +++ b/selfdrive/ui/qt/spinner.cc @@ -111,7 +111,7 @@ void Spinner::update(int n) { } int main(int argc, char *argv[]) { - initApp(); + initApp(argc, argv); QApplication a(argc, argv); Spinner spinner; setMainWindow(&spinner); diff --git a/selfdrive/ui/qt/text.cc b/selfdrive/ui/qt/text.cc index cb69cc082b8b37..04fda35483aba8 100644 --- a/selfdrive/ui/qt/text.cc +++ b/selfdrive/ui/qt/text.cc @@ -11,7 +11,7 @@ #include "selfdrive/ui/qt/widgets/scrollview.h" int main(int argc, char *argv[]) { - initApp(); + initApp(argc, argv); QApplication a(argc, argv); QWidget window; setMainWindow(&window); diff --git a/selfdrive/ui/qt/util.cc b/selfdrive/ui/qt/util.cc index 16d5c174b591bf..967b7d15d13f48 100644 --- a/selfdrive/ui/qt/util.cc +++ b/selfdrive/ui/qt/util.cc @@ -89,9 +89,18 @@ void setQtSurfaceFormat() { QSurfaceFormat::setDefaultFormat(fmt); } -void initApp() { +void initApp(int argc, char *argv[]) { Hardware::set_display_power(true); Hardware::set_brightness(65); + +#ifdef __APPLE__ + { + // Get the devicePixelRatio, and scale accordingly to maintain 1:1 rendering + QApplication tmp(argc, argv); + qputenv("QT_SCALE_FACTOR", QString::number(1.0 / tmp.devicePixelRatio() ).toLocal8Bit()); + } +#endif + setQtSurfaceFormat(); if (Hardware::EON()) { QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); diff --git a/selfdrive/ui/qt/util.h b/selfdrive/ui/qt/util.h index 1b9461fabf2f3a..813777710a73bb 100644 --- a/selfdrive/ui/qt/util.h +++ b/selfdrive/ui/qt/util.h @@ -19,6 +19,6 @@ void clearLayout(QLayout* layout); void setQtSurfaceFormat(); QString timeAgo(const QDateTime &date); void swagLogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); -void initApp(); +void initApp(int argc, char *argv[]); QWidget* topWidget (QWidget* widget); QPixmap loadPixmap(const QString &fileName, const QSize &size = {}, Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio); diff --git a/selfdrive/ui/watch3.cc b/selfdrive/ui/watch3.cc index aeabfe110e6170..1752ce9b6dd7b5 100644 --- a/selfdrive/ui/watch3.cc +++ b/selfdrive/ui/watch3.cc @@ -6,7 +6,7 @@ #include "selfdrive/ui/qt/widgets/cameraview.h" int main(int argc, char *argv[]) { - setQtSurfaceFormat(); + initApp(argc, argv); QApplication a(argc, argv); QWidget w;