Skip to content

Commit

Permalink
add switch -opengl to switch various opengl modes
Browse files Browse the repository at this point in the history
  • Loading branch information
akdor1154 committed Mar 13, 2015
1 parent 583a5c8 commit 296d276
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QCommandLineOption> options = QList<QCommandLineOption>({
{{"clear-cache","C"}, "Clear cached request data"},
{{"uri","u"}, "Set starting url to <uri>", "uri"},
{{"monitor", "m"}, "Display window on the <n>th monitor", "n"},
{{"config", "c"}, "Use <file> to configure this instance of qt-webengine-kiosk", "file"}
{{"config", "c"}, "Use <file> to configure this instance of qt-webengine-kiosk", "file"},
{"opengl", QString()+"Use <"+glModes.join('|')+"> for hardware accelerated rendering", "system"}
});

parser.addOptions(options);
Expand Down
25 changes: 25 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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()));
Expand Down
3 changes: 3 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 296d276

Please sign in to comment.