diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-05-29 17:24:33 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-06-04 07:03:45 +0000 |
commit | d910065eea4481929dbc86bb3f5e3f1f5c15484e (patch) | |
tree | 9ea91bec97f0c859733e82a64071a69023ada99a /tools/qmlscene/main.cpp | |
parent | 7c22994176d37b3f5c9505635b63ae502aafdfec (diff) |
qmlscene: Add option --verbose to obtain diagnostic output.
Print the build information and connect to
QQuickWindow::openglContextCreated() to print information on the
GL driver (similar to qtdiag).
Set a window title indicating render type and Qt version.
Task-number: QTBUG-46030
Change-Id: Ib4376126bf9c63f4cab8cb530ff1da66394b634b
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'tools/qmlscene/main.cpp')
-rw-r--r-- | tools/qmlscene/main.cpp | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp index ad57454651..fe01b92244 100644 --- a/tools/qmlscene/main.cpp +++ b/tools/qmlscene/main.cpp @@ -40,6 +40,7 @@ #include <QtCore/qtextstream.h> #include <QtGui/QGuiApplication> +#include <QtGui/QOpenGLFunctions> #include <QtQml/qqml.h> #include <QtQml/qqmlengine.h> @@ -148,6 +149,7 @@ struct Options , quitImmediately(false) , resizeViewToRootItem(false) , multisample(false) + , verbose(false) { // QtWebEngine needs a shared context in order for the GPU thread to // upload textures. @@ -166,6 +168,7 @@ struct Options bool quitImmediately; bool resizeViewToRootItem; bool multisample; + bool verbose; QVector<Qt::ApplicationAttribute> applicationAttributes; QString translationFile; }; @@ -355,6 +358,7 @@ static void usage() puts(" --desktop..........................Force use of desktop GL (AA_UseDesktopOpenGL)"); puts(" --gles.............................Force use of GLES (AA_UseOpenGLES)"); puts(" --software.........................Force use of software rendering (AA_UseOpenGLES)"); + puts(" --verbose..........................Print version and graphical diagnostics for the run-time"); puts(" -I <path> ........................ Add <path> to the list of import paths"); puts(" -P <path> ........................ Add <path> to the list of plugin paths"); puts(" -translation <translationfile> ... Set the language to run in"); @@ -363,6 +367,55 @@ static void usage() exit(1); } +// Listen on GL context creation of the QQuickWindow in order to print diagnostic output. +class DiagnosticGlContextCreationListener : public QObject { + Q_OBJECT +public: + explicit DiagnosticGlContextCreationListener(QQuickWindow *window) : QObject(window) + { + connect(window, &QQuickWindow::openglContextCreated, + this, &DiagnosticGlContextCreationListener::onOpenGlContextCreated); + } + +private slots: + void onOpenGlContextCreated(QOpenGLContext *context) + { + context->makeCurrent(qobject_cast<QQuickWindow *>(parent())); + QOpenGLFunctions functions(context); + QByteArray output = "Vendor : "; + output += reinterpret_cast<const char *>(functions.glGetString(GL_VENDOR)); + output += "\nRenderer: "; + output += reinterpret_cast<const char *>(functions.glGetString(GL_RENDERER)); + output += "\nVersion : "; + output += reinterpret_cast<const char *>(functions.glGetString(GL_VERSION)); + output += "\nLanguage: "; + output += reinterpret_cast<const char *>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION)); + puts(output.constData()); + context->doneCurrent(); + deleteLater(); + } +}; + +static void setWindowTitle(bool verbose, const QObject *topLevel, QWindow *window) +{ + const QString oldTitle = window->title(); + QString newTitle = oldTitle; + if (newTitle.isEmpty()) { + newTitle = QLatin1String("qmlscene"); + if (!qobject_cast<const QWindow *>(topLevel) && !topLevel->objectName().isEmpty()) + newTitle += QLatin1String(": ") + topLevel->objectName(); + } + if (verbose) { + newTitle += QLatin1String(" [Qt ") + QLatin1String(QT_VERSION_STR) + QLatin1Char(' ') + + QGuiApplication::platformName() + QLatin1Char(' '); + newTitle += QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL + ? QLatin1String("GL") : QLatin1String("GLES"); + newTitle += QLatin1Char(']'); + } + if (oldTitle != newTitle) + window->setTitle(newTitle); +} + int main(int argc, char ** argv) { Options options; @@ -402,6 +455,8 @@ int main(int argc, char ** argv) options.applicationAttributes.append(Qt::AA_UseSoftwareOpenGL); else if (lowerArgument == QLatin1String("--desktop")) options.applicationAttributes.append(Qt::AA_UseDesktopOpenGL); + else if (lowerArgument == QLatin1String("--verbose")) + options.verbose = true; else if (lowerArgument == QLatin1String("-i") && i + 1 < argc) imports.append(QString::fromLatin1(argv[++i])); else if (lowerArgument == QLatin1String("-p") && i + 1 < argc) @@ -456,6 +511,9 @@ int main(int argc, char ** argv) int exitCode = 0; + if (options.verbose) + puts(QLibraryInfo::build()); + if (!options.file.isEmpty()) { if (!options.versionDetection || checkVersion(options.file)) { #ifndef QT_NO_TRANSLATION @@ -498,8 +556,6 @@ int main(int argc, char ** argv) QQuickView* qxView = new QQuickView(&engine, NULL); window.reset(qxView); // Set window default properties; the qml can still override them - QString oname = contentItem->objectName(); - window->setTitle(oname.isEmpty() ? QString::fromLatin1("qmlscene") : QString::fromLatin1("qmlscene: ") + oname); if (options.resizeViewToRootItem) qxView->setResizeMode(QQuickView::SizeViewToRootObject); else @@ -509,6 +565,9 @@ int main(int argc, char ** argv) } if (window) { + setWindowTitle(options.verbose, topLevel, window.data()); + if (options.verbose) + new DiagnosticGlContextCreationListener(window.data()); QSurfaceFormat surfaceFormat = window->requestedFormat(); if (options.multisample) surfaceFormat.setSamples(16); @@ -550,3 +609,5 @@ int main(int argc, char ** argv) return exitCode; } + +#include "main.moc" |