diff --git a/src/main.cpp b/src/main.cpp index c3d2c9b..c1e600b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,11 +47,18 @@ int main(int argc, char * argv[]) parser.addHelpOption(); parser.addVersionOption(); + QStringList glModes; + QMetaEnum glMode = MainWindow::staticMetaObject.enumerator(MainWindow::staticMetaObject.indexOfEnumerator("GlMode")); + for (int value = 0; value < glMode.keyCount(); value++) { + glModes.append(QString(glMode.valueToKey(value))); + } + QList options = QList({ {{"clear-cache","C"}, "Clear cached request data"}, {{"uri","u"}, "Set starting url to ", "uri"}, {{"monitor", "m"}, "Display window on the th monitor", "n"}, - {{"config", "c"}, "Use to configure this instance of qt-webengine-kiosk", "file"} + {{"config", "c"}, "Use to configure this instance of qt-webengine-kiosk", "file"}, + {"opengl", QString()+"Use <"+glModes.join('|')+"> for hardware accelerated rendering", "system"} }); parser.addOptions(options); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 889ae2d..fe6e996 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -92,6 +92,7 @@ void MainWindow::init(QCommandLineParser &options) {"application/name", "Qt WebEngine Kiosk"}, {"application/version", VERSION}, {"application/icon", ICON }, + {"application/opengl_mode", "auto"}, {"proxy/enable", false }, {"proxy/system", true }, {"proxy/host", "proxy.example.com" }, @@ -176,6 +177,30 @@ void MainWindow::init(QCommandLineParser &options) manualScreen = ok ? monitorNum : 0; } + QMetaEnum glModeEnum = MainWindow::staticMetaObject.enumerator(MainWindow::staticMetaObject.indexOfEnumerator("GlMode")); + + QString glMode; + if ((glMode = options.value("opengl")).isEmpty()) { + glMode = mainSettings->value("application/opengl_mode").toString(); + } + switch (glModeEnum.keyToValue(glMode.toUpper().toLatin1())) { + case NATIVE: + qApp->setAttribute(Qt::AA_UseDesktopOpenGL); + qDebug() << "attempting to use native OpenGL"; + break; + case ANGLE: + qApp->setAttribute(Qt::AA_UseOpenGLES); + qDebug() << "attempting to use OpenGL ES (or ANGLE, on Windows)"; + break; + case SOFTWARE: + qDebug() << "using software rendering"; + qApp->setAttribute(Qt::AA_UseSoftwareOpenGL); + break; + case AUTO: + default: + break; + } + if (mainSettings->value("signals/enable").toBool()) { connect(handler, SIGNAL(sigUSR1()), SLOT(unixSignalUsr1())); connect(handler, SIGNAL(sigUSR2()), SLOT(unixSignalUsr2())); diff --git a/src/mainwindow.h b/src/mainwindow.h index 3d8c13a..b6e0a87 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -69,11 +69,13 @@ struct keyFunction { class MainWindow : public QMainWindow { Q_OBJECT + Q_ENUMS(GlMode) public: explicit MainWindow(); void init(QCommandLineParser&); + enum GlMode { AUTO, NATIVE, ANGLE, SOFTWARE }; void clearCache(); void clearCacheOnExit(); @@ -118,6 +120,7 @@ protected slots: void keyPressEvent(QKeyEvent *event); void updatePixelRatio(); + private: WebView* view; // Webkit Page View QProgressBar *loadProgress; // progress bar to display page loading