Skip to content

Log graphics API that is in use by the Qt Quick #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ QT_QRC_LOCALE = qt/bitcoin_locale.qrc
BITCOIN_QT_H = \
qml/bitcoin.h \
qml/nodemodel.h \
qml/util.h \
qt/addressbookpage.h \
qt/addresstablemodel.h \
qt/askpassphrasedialog.h \
Expand Down Expand Up @@ -284,7 +285,8 @@ BITCOIN_QT_WALLET_CPP = \

BITCOIN_QML_BASE_CPP = \
qml/bitcoin.cpp \
qml/nodemodel.cpp
qml/nodemodel.cpp \
qml/util.cpp

QML_QRC_CPP = qml/qrc_bitcoin.cpp
QML_QRC = qml/bitcoin_qml.qrc
Expand Down
10 changes: 10 additions & 0 deletions src/qml/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <node/ui_interface.h>
#include <noui.h>
#include <qml/nodemodel.h>
#include <qml/util.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
#include <qt/initexecutor.h>
Expand All @@ -19,9 +20,11 @@
#include <boost/signals2/connection.hpp>
#include <memory>

#include <QDebug>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickWindow>
#include <QStringLiteral>
#include <QUrl>

Expand Down Expand Up @@ -146,5 +149,12 @@ int QmlGuiMain(int argc, char* argv[])
return EXIT_FAILURE;
}

auto window = qobject_cast<QQuickWindow*>(engine.rootObjects().first());
if (!window) {
return EXIT_FAILURE;
}

qInfo() << "Graphics API in use:" << QmlUtil::GraphicsApi(window);

return qGuiApp->exec();
}
34 changes: 34 additions & 0 deletions src/qml/util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <qml/util.h>

#include <string>

#include <QQuickWindow>
#include <QSGRendererInterface>
#include <QString>

namespace QmlUtil {

QString GraphicsApi(QQuickWindow* window)
{
switch (window->rendererInterface()->graphicsApi()) {
case QSGRendererInterface::Unknown: return "Unknown";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've spent hours and hours digging through Qt code to figure out if there is a better way than manually maintaining these strings. Sadly, there is not. For now, this allows us to conveniently debug.

Note: Let's revisit this at some point in the future

case QSGRendererInterface::Software: return "The Qt Quick 2D Renderer";
case QSGRendererInterface::OpenGL: return "OpenGL ES 2.0 or higher";
case QSGRendererInterface::Direct3D12: return "Direct3D 12";
case QSGRendererInterface::OpenVG: return "OpenVG via EGL";
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the isApiRhiBased function. It was introduced in Qt 5.14.

This check is then appropriate and allows for a simplified control flow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jarolrod still needs #if as the cases below don't exist in <5.14.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, i meant that the way it is done here simplifies the control flow compared to if we used the function.

case QSGRendererInterface::OpenGLRhi: return "OpenGL ES 2.0 or higher via a graphics abstraction layer";
case QSGRendererInterface::Direct3D11Rhi: return "Direct3D 11 via a graphics abstraction layer";
case QSGRendererInterface::VulkanRhi: return "Vulkan 1.0 via a graphics abstraction layer";
case QSGRendererInterface::MetalRhi: return "Metal via a graphics abstraction layer";
case QSGRendererInterface::NullRhi: return "Null (no output) via a graphics abstraction layer";
#endif
} // no default case, so the compiler can warn about missing cases
assert(false);
}

} // namespace QmlUtil
27 changes: 27 additions & 0 deletions src/qml/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_QML_UTIL_H
#define BITCOIN_QML_UTIL_H

#include <QString>
#include <QtGlobal>

QT_BEGIN_NAMESPACE
class QQuickWindow;
QT_END_NAMESPACE

/**
* Utility functions used by the QML-based Bitcoin Core GUI.
*/
namespace QmlUtil {
/**
* Returns a human-readable description of the graphics API
* that is in use by the Qt Quick scene graph renderer.
*/
QString GraphicsApi(QQuickWindow* window);

} // namespace QmlUtil

#endif // BITCOIN_QML_UTIL_H
3 changes: 2 additions & 1 deletion src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ void LogQtInfo()
}

#if USE_QML
LogPrintf("QQuickStyle: %s\n", QQuickStyle::name().toStdString());
const auto style = QQuickStyle::name().toStdString();
LogPrintf("QQuickStyle: %s\n", style.empty() ? "Default" : style);
#else
LogPrintf("Style: %s / %s\n", QApplication::style()->objectName().toStdString(), QApplication::style()->metaObject()->className());
#endif // USE_QML
Expand Down