aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2016-05-02 21:38:20 +0200
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2016-05-03 10:12:40 +0000
commit84fb780d830764bcaa53478a5c5c464865897640 (patch)
tree35531692fdec60091feca3e51d8e9da05510f661 /src
parent3551093f426ef7bbc222b543f573d5d341a43d8e (diff)
Introduce RendererInfo
Modeled after OpenGLInfo, RendererInfo.api is an easy to use attached property that reports the current graphics API as long as the item is associated with a window that has the scenegraph initialized. Applications should not worry about this in general since they should target one given API, however tests, examples and some advanced use cases will find this handy. RendererInfo is also a great place to expose other properties in the future. Change-Id: Ie3411b8820fc4b74efd1b1d0143e936886f62d74 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/items.pri6
-rw-r--r--src/quick/items/qquickitemsmodule.cpp6
-rw-r--r--src/quick/items/qquickrendererinfo.cpp129
-rw-r--r--src/quick/items/qquickrendererinfo_p.h100
-rw-r--r--src/quick/scenegraph/coreapi/qsgrendererinterface.h4
5 files changed, 238 insertions, 7 deletions
diff --git a/src/quick/items/items.pri b/src/quick/items/items.pri
index 61d81f94be..1c17e7e34d 100644
--- a/src/quick/items/items.pri
+++ b/src/quick/items/items.pri
@@ -77,7 +77,8 @@ HEADERS += \
$$PWD/qquickshadereffect_p.h \
$$PWD/qquickgenericshadereffect_p.h \
$$PWD/qquickrendercontrol.h \
- $$PWD/qquickrendercontrol_p.h
+ $$PWD/qquickrendercontrol_p.h \
+ $$PWD/qquickrendererinfo_p.h
SOURCES += \
$$PWD/qquickevents.cpp \
@@ -130,7 +131,8 @@ SOURCES += \
$$PWD/qquickshadereffectmesh.cpp \
$$PWD/qquickshadereffect.cpp \
$$PWD/qquickgenericshadereffect.cpp \
- $$PWD/qquickrendercontrol.cpp
+ $$PWD/qquickrendercontrol.cpp \
+ $$PWD/qquickrendererinfo.cpp
# Items that depend on OpenGL Renderer
contains(QT_CONFIG, opengl(es1|es2)?) {
diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp
index fa01c8c563..5f5809b6f2 100644
--- a/src/quick/items/qquickitemsmodule.cpp
+++ b/src/quick/items/qquickitemsmodule.cpp
@@ -80,6 +80,7 @@
# include "qquickanimatedsprite_p.h"
# include "qquickopenglinfo_p.h"
#endif
+#include "qquickrendererinfo_p.h"
#include "qquickshadereffect_p.h"
#include "qquickshadereffectmesh_p.h"
#include "qquickdrag_p.h"
@@ -292,9 +293,10 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor)
qmlRegisterType<QQuickTextInput, 7>(uri, 2, 7, "TextInput");
qmlRegisterType<QQuickTextEdit, 7>(uri, 2, 7, "TextEdit");
- qmlRegisterType<QQuickShaderEffect, 2>(uri, 2, 8, "ShaderEffect");
-
qmlRegisterUncreatableType<QQuickMouseEvent, 7>(uri, 2, 7, nullptr, QQuickMouseEvent::tr("MouseEvent is only available within handlers in MouseArea"));
+
+ qmlRegisterType<QQuickShaderEffect, 2>(uri, 2, 8, "ShaderEffect");
+ qmlRegisterUncreatableType<QQuickRendererInfo>(uri, 2, 8,"RendererInfo", QQuickRendererInfo::tr("RendererInfo is only available via attached properties"));
}
static void initResources()
diff --git a/src/quick/items/qquickrendererinfo.cpp b/src/quick/items/qquickrendererinfo.cpp
new file mode 100644
index 0000000000..e41f4ebbae
--- /dev/null
+++ b/src/quick/items/qquickrendererinfo.cpp
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickrendererinfo_p.h"
+#include "qquickwindow.h"
+#include "qquickitem.h"
+#include <qsgrendererinterface.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmltype RendererInfo
+ \instantiates QQuickRendererInfo
+ \inqmlmodule QtQuick
+ \ingroup qtquick-effects
+ \since 5.8
+ \since QtQuick 2.8
+ \brief Provides information about the used Qt Quick backend
+
+ The RendererInfo attached type provides information about the scenegraph
+ backend used to render the contents of the associated window.
+
+ If the item to which the properties are attached is not currently
+ associated with any window, the properties are set to default values. When
+ the associated window changes, the properties will update.
+
+ \sa OpenGLInfo, ShaderEffect
+ */
+
+QQuickRendererInfo::QQuickRendererInfo(QQuickItem *item)
+ : QObject(item)
+ , m_window(0)
+ , m_api(Unknown)
+{
+ connect(item, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(setWindow(QQuickWindow*)));
+ setWindow(item->window());
+}
+
+QQuickRendererInfo *QQuickRendererInfo::qmlAttachedProperties(QObject *object)
+{
+ if (QQuickItem *item = qobject_cast<QQuickItem *>(object))
+ return new QQuickRendererInfo(item);
+
+ return nullptr;
+}
+
+/*!
+ \qmlproperty enumeration QtQuick::RendererInfo::api
+
+ This property describes the graphics API that is currently in use.
+
+ The possible values are:
+ \list
+ \li RendererInfo.Unknown - the default value when no active scenegraph is associated with the item
+ \li RendererInfo.Software - Qt Quick's software renderer based on QPainter with the raster paint engine
+ \li RendererInfo.OpenGL - OpenGL or OpenGL ES
+ \li RendererInfo.Direct3D12 - Direct3D 12
+ \endlist
+ */
+
+void QQuickRendererInfo::updateInfo()
+{
+ GraphicsAPI newAPI = Unknown;
+
+ if (m_window && m_window->isSceneGraphInitialized()) {
+ QSGRendererInterface *rif = m_window->rendererInterface();
+ if (rif)
+ newAPI = GraphicsAPI(rif->graphicsAPI()); // this function is safe to call on the gui/main thread too
+ }
+
+ if (m_api != newAPI) {
+ m_api = newAPI;
+ emit apiChanged();
+ }
+}
+
+void QQuickRendererInfo::setWindow(QQuickWindow *window)
+{
+ if (m_window != window) {
+ if (m_window) {
+ disconnect(m_window, SIGNAL(sceneGraphInitialized()), this, SLOT(updateInfo()));
+ disconnect(m_window, SIGNAL(sceneGraphInvalidated()), this, SLOT(updateInfo()));
+ }
+ if (window) {
+ connect(window, SIGNAL(sceneGraphInitialized()), this, SLOT(updateInfo()));
+ connect(window, SIGNAL(sceneGraphInvalidated()), this, SLOT(updateInfo()));
+ }
+ m_window = window;
+ }
+ updateInfo();
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/items/qquickrendererinfo_p.h b/src/quick/items/qquickrendererinfo_p.h
new file mode 100644
index 0000000000..d76f4010e0
--- /dev/null
+++ b/src/quick/items/qquickrendererinfo_p.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKRENDERERINFO_P_H
+#define QQUICKRENDERERINFO_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+#include <QtCore/qpointer.h>
+#include <QtQml/qqml.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickItem;
+class QQuickWindow;
+
+class QQuickRendererInfo : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(GraphicsAPI api READ api NOTIFY apiChanged FINAL)
+
+public:
+ // must match QSGRendererInterface
+ enum GraphicsAPI {
+ Unknown,
+ Software,
+ OpenGL,
+ Direct3D12
+ };
+ Q_ENUM(GraphicsAPI)
+
+ QQuickRendererInfo(QQuickItem *item = 0);
+
+ static QQuickRendererInfo *qmlAttachedProperties(QObject *object);
+
+ GraphicsAPI api() const { return m_api; }
+
+Q_SIGNALS:
+ void apiChanged();
+
+private Q_SLOTS:
+ void updateInfo();
+ void setWindow(QQuickWindow *window);
+
+private:
+ QPointer<QQuickWindow> m_window;
+ GraphicsAPI m_api;
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPEINFO(QQuickRendererInfo, QML_HAS_ATTACHED_PROPERTIES)
+
+#endif // QQUICKRENDERERINFO_P_H
diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.h b/src/quick/scenegraph/coreapi/qsgrendererinterface.h
index c4a145dd0f..a34b4b3c26 100644
--- a/src/quick/scenegraph/coreapi/qsgrendererinterface.h
+++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.h
@@ -51,9 +51,7 @@ public:
Unknown,
Software,
OpenGL,
- Direct3D12,
- Vulkan,
- Metal
+ Direct3D12
};
enum Resource {