From 625bf79623e152946a627d1c30caeb180ce7b49d Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Wed, 9 Jun 2021 20:09:49 +0800 Subject: [PATCH] qt/util.h : add new function setQtSurfaceFormat (#21206) old-commit-hash: 9429bd27835bf2b9e2df192c888d3600ef784cef --- selfdrive/ui/main.cc | 11 ++--------- selfdrive/ui/qt/spinner.cc | 11 ++--------- selfdrive/ui/qt/util.h | 12 ++++++++++++ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/selfdrive/ui/main.cc b/selfdrive/ui/main.cc index dab8d66540..901899e39a 100644 --- a/selfdrive/ui/main.cc +++ b/selfdrive/ui/main.cc @@ -3,18 +3,11 @@ #include "selfdrive/hardware/hw.h" #include "selfdrive/ui/qt/qt_window.h" +#include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/window.h" int main(int argc, char *argv[]) { - QSurfaceFormat fmt; -#ifdef __APPLE__ - fmt.setVersion(3, 2); - fmt.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); - fmt.setRenderableType(QSurfaceFormat::OpenGL); -#else - fmt.setRenderableType(QSurfaceFormat::OpenGLES); -#endif - QSurfaceFormat::setDefaultFormat(fmt); + setQtSurfaceFormat(); if (Hardware::EON()) { QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); diff --git a/selfdrive/ui/qt/spinner.cc b/selfdrive/ui/qt/spinner.cc index f16be965ba..822a8c9f8a 100644 --- a/selfdrive/ui/qt/spinner.cc +++ b/selfdrive/ui/qt/spinner.cc @@ -12,6 +12,7 @@ #include "selfdrive/hardware/hw.h" #include "selfdrive/ui/qt/qt_window.h" +#include "selfdrive/ui/qt/util.h" TrackWidget::TrackWidget(QWidget *parent) : QWidget(parent) { setFixedSize(spinner_size); @@ -114,15 +115,7 @@ void Spinner::update(int n) { } int main(int argc, char *argv[]) { - QSurfaceFormat fmt; -#ifdef __APPLE__ - fmt.setVersion(3, 2); - fmt.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); - fmt.setRenderableType(QSurfaceFormat::OpenGL); -#else - fmt.setRenderableType(QSurfaceFormat::OpenGLES); -#endif - QSurfaceFormat::setDefaultFormat(fmt); + setQtSurfaceFormat(); Hardware::set_display_power(true); Hardware::set_brightness(65); diff --git a/selfdrive/ui/qt/util.h b/selfdrive/ui/qt/util.h index c8c33504de..8cc1e46ebb 100644 --- a/selfdrive/ui/qt/util.h +++ b/selfdrive/ui/qt/util.h @@ -42,3 +42,15 @@ inline QString timeAgo(const QDateTime &date) { return s; } + +inline void setQtSurfaceFormat() { + QSurfaceFormat fmt; +#ifdef __APPLE__ + fmt.setVersion(3, 2); + fmt.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); + fmt.setRenderableType(QSurfaceFormat::OpenGL); +#else + fmt.setRenderableType(QSurfaceFormat::OpenGLES); +#endif + QSurfaceFormat::setDefaultFormat(fmt); +}