Skip to content

Commit

Permalink
MacOS: ensure 1:1 rendering on HiDPI screens (commaai#23860)
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm authored and budney committed Mar 27, 2022
1 parent 315460c commit c605408
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion selfdrive/ui/installer/installer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/ui/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/ui/qt/setup/updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/ui/qt/spinner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/ui/qt/text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion selfdrive/ui/qt/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/ui/qt/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion selfdrive/ui/watch3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c605408

Please sign in to comment.