From: J-P Nurmi Date: Sat, 9 Aug 2014 21:42:20 +0000 (+0200) Subject: Add OpenGLInfo attached type X-Git-Tag: v5.3.99+beta1~181 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af6ca36c8362bcda4ebe3a3bf369c85aaa98f47c;p=platform%2Fupstream%2Fqtdeclarative.git Add OpenGLInfo attached type [ChangeLog][QtQuick] Introduced OpenGLInfo attached type that provides information about the currently used OpenGL version. Change-Id: Ibdf365decf9d6331cf91c0bf541e493ced02a417 Reviewed-by: Laszlo Agocs Reviewed-by: Gunnar Sletta --- diff --git a/src/quick/items/items.pri b/src/quick/items/items.pri index 87e2212..0b98782 100644 --- a/src/quick/items/items.pri +++ b/src/quick/items/items.pri @@ -78,7 +78,8 @@ HEADERS += \ $$PWD/qquickframebufferobject.h \ $$PWD/qquickitemgrabresult.h \ $$PWD/qquickrendercontrol.h \ - $$PWD/qquickrendercontrol_p.h + $$PWD/qquickrendercontrol_p.h \ + $$PWD/qquickopenglinfo_p.h SOURCES += \ $$PWD/qquickevents.cpp \ @@ -133,7 +134,8 @@ SOURCES += \ $$PWD/qquickwindowattached.cpp \ $$PWD/qquickframebufferobject.cpp \ $$PWD/qquickitemgrabresult.cpp \ - $$PWD/qquickrendercontrol.cpp + $$PWD/qquickrendercontrol.cpp \ + $$PWD/qquickopenglinfo.cpp SOURCES += \ $$PWD/qquickshadereffect.cpp \ diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index d867139..b325158 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -83,6 +83,7 @@ #include "qquickdrag_p.h" #include "qquickdroparea_p.h" #include "qquickmultipointtoucharea_p.h" +#include "qquickopenglinfo_p.h" #include #include @@ -273,6 +274,7 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType(uri, 2, 4, "ListView"); qmlRegisterType(uri, 2, 4, "MouseArea"); qmlRegisterType(uri, 2, 4, "ShaderEffect"); + qmlRegisterUncreatableType(uri, 2, 4,"OpenGLInfo", QQuickOpenGLInfo::tr("OpenGLInfo is only available via attached properties")); } static void initResources() diff --git a/src/quick/items/qquickopenglinfo.cpp b/src/quick/items/qquickopenglinfo.cpp new file mode 100644 index 0000000..dbaa92a --- /dev/null +++ b/src/quick/items/qquickopenglinfo.cpp @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BlackBerry Ltd. +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickopenglinfo_p.h" +#include "qopenglcontext.h" +#include "qquickwindow.h" +#include "qquickitem.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype OpenGLInfo + \instantiates QQuickOpenGLInfo + \inqmlmodule QtQuick + \ingroup qtquick-effects + \since 5.4 + \brief Provides information about the used OpenGL version + + The OpenGLInfo attached type provides information about the OpenGL + version being used to render the surface of the attachee item. + + If the attachee item is not currently associated with any graphical + surface, the properties are set to the values of the default surface + format. When it becomes associated with a surface, all properties + will update. + + \sa ShaderEffect + */ +QQuickOpenGLInfo::QQuickOpenGLInfo(QQuickItem *item) + : QObject(item) + , m_window(0) + , m_majorVersion(2) + , m_minorVersion(0) + , m_profile(NoProfile) + , m_renderableType(Unspecified) +{ + connect(item, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(setWindow(QQuickWindow*))); + setWindow(item->window()); +} + +/*! + \qmlproperty int QtQuick::OpenGLInfo::majorVersion + + This property holds the major OpenGL version. + + The default version is \c 2.0. + + \sa minorVersion, profile + */ +int QQuickOpenGLInfo::majorVersion() const +{ + return m_majorVersion; +} + +/*! + \qmlproperty int QtQuick::OpenGLInfo::minorVersion + + This property holds the minor OpenGL version. + + The default version is \c 2.0. + + \sa majorVersion, profile + */ +int QQuickOpenGLInfo::minorVersion() const +{ + return m_minorVersion; +} + +/*! + \qmlproperty enumeration QtQuick::OpenGLInfo::profile + + This property holds the configured OpenGL context profile. + + The possible values are: + \list + \li OpenGLInfo.NoProfile (default) - OpenGL version is lower than 3.2. + \li OpenGLInfo.CoreProfile - Functionality deprecated in OpenGL version 3.0 is not available. + \li OpenGLInfo.CompatibilityProfile - Functionality from earlier OpenGL versions is available. + \endlist + + Reusable QML components will typically use this property in bindings in order to + choose between core and non core profile compatible shader sources. + + \sa majorVersion, minorVersion + */ +QQuickOpenGLInfo::ContextProfile QQuickOpenGLInfo::profile() const +{ + return m_profile; +} + +/*! + \qmlproperty enumeration QtQuick::OpenGLInfo::renderableType + + This property holds the renderable type. + + The possible values are: + \list + \li OpenGLInfo.Unspecified (default) - Unspecified rendering method + \li OpenGLInfo.OpenGL - Desktop OpenGL rendering + \li OpenGLInfo.OpenGLES - OpenGL ES rendering + \endlist + */ +QQuickOpenGLInfo::RenderableType QQuickOpenGLInfo::renderableType() const +{ + return m_renderableType; +} + +QQuickOpenGLInfo *QQuickOpenGLInfo::qmlAttachedProperties(QObject *object) +{ + if (QQuickItem *item = qobject_cast(object)) + return new QQuickOpenGLInfo(item); + return 0; +} + +void QQuickOpenGLInfo::updateFormat() +{ + QOpenGLContext *context = 0; + if (m_window) + context = m_window->openglContext(); + QSurfaceFormat format = context ? context->format() : QSurfaceFormat::defaultFormat(); + + if (m_majorVersion != format.majorVersion()) { + m_majorVersion = format.majorVersion(); + emit majorVersionChanged(); + } + + if (m_minorVersion != format.minorVersion()) { + m_minorVersion = format.minorVersion(); + emit minorVersionChanged(); + } + + ContextProfile profile = static_cast(format.profile()); + if (m_profile != profile) { + m_profile = profile; + emit profileChanged(); + } + + RenderableType renderableType = static_cast(format.renderableType()); + if (m_renderableType != renderableType) { + m_renderableType = renderableType; + emit renderableTypeChanged(); + } +} + +void QQuickOpenGLInfo::setWindow(QQuickWindow *window) +{ + if (m_window != window) { + if (m_window) { + disconnect(m_window, SIGNAL(sceneGraphInitialized()), this, SLOT(updateFormat())); + disconnect(m_window, SIGNAL(sceneGraphInvalidated()), this, SLOT(updateFormat())); + } + if (window) { + connect(window, SIGNAL(sceneGraphInitialized()), this, SLOT(updateFormat())); + connect(window, SIGNAL(sceneGraphInvalidated()), this, SLOT(updateFormat())); + } + m_window = window; + } + updateFormat(); +} + +QT_END_NAMESPACE diff --git a/src/quick/items/qquickopenglinfo_p.h b/src/quick/items/qquickopenglinfo_p.h new file mode 100644 index 0000000..70684a2 --- /dev/null +++ b/src/quick/items/qquickopenglinfo_p.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BlackBerry Ltd. +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKOPENGLINFO_P_H +#define QQUICKOPENGLINFO_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 +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickItem; +class QQuickWindow; + +class QQuickOpenGLInfo : public QObject +{ + Q_OBJECT + Q_PROPERTY(int majorVersion READ majorVersion NOTIFY majorVersionChanged FINAL) + Q_PROPERTY(int minorVersion READ minorVersion NOTIFY minorVersionChanged FINAL) + Q_PROPERTY(ContextProfile profile READ profile NOTIFY profileChanged FINAL) + Q_PROPERTY(RenderableType renderableType READ renderableType NOTIFY renderableTypeChanged FINAL) + Q_ENUMS(ContextProfile RenderableType) + +public: + QQuickOpenGLInfo(QQuickItem *item = 0); + + int majorVersion() const; + int minorVersion() const; + + // keep in sync with QSurfaceFormat::OpenGLContextProfile + enum ContextProfile { + NoProfile = QSurfaceFormat::NoProfile, + CoreProfile = QSurfaceFormat::CoreProfile, + CompatibilityProfile = QSurfaceFormat::CompatibilityProfile + }; + ContextProfile profile() const; + + // keep in sync with QSurfaceFormat::RenderableType + enum RenderableType { + Unspecified = QSurfaceFormat::DefaultRenderableType, + OpenGL = QSurfaceFormat::OpenGL, + OpenGLES = QSurfaceFormat::OpenGLES + }; + RenderableType renderableType() const; + + static QQuickOpenGLInfo *qmlAttachedProperties(QObject *object); + +Q_SIGNALS: + void majorVersionChanged(); + void minorVersionChanged(); + void profileChanged(); + void renderableTypeChanged(); + +private Q_SLOTS: + void updateFormat(); + void setWindow(QQuickWindow *window); + +private: + QPointer m_window; + int m_majorVersion; + int m_minorVersion; + ContextProfile m_profile; + RenderableType m_renderableType; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickOpenGLInfo, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKOPENGLINFO_P_H diff --git a/src/quick/items/qquickshadereffect.cpp b/src/quick/items/qquickshadereffect.cpp index 9dfce3f..148c33d 100644 --- a/src/quick/items/qquickshadereffect.cpp +++ b/src/quick/items/qquickshadereffect.cpp @@ -651,6 +651,8 @@ void QQuickShaderEffectCommon::propertyChanged(QQuickItem *item, int mappedId, \note Scene Graph textures have origin in the top-left corner rather than bottom-left which is common in OpenGL. + + For information about the GLSL version being used, see \l QtQuick::OpenGLInfo. */ QQuickShaderEffect::QQuickShaderEffect(QQuickItem *parent) diff --git a/tests/auto/quick/qquickopenglinfo/data/basic.qml b/tests/auto/quick/qquickopenglinfo/data/basic.qml new file mode 100644 index 0000000..b484479 --- /dev/null +++ b/tests/auto/quick/qquickopenglinfo/data/basic.qml @@ -0,0 +1,8 @@ +import QtQuick 2.4 + +Item { + property int majorVersion: OpenGLInfo.majorVersion + property int minorVersion: OpenGLInfo.minorVersion + property int profile: OpenGLInfo.profile + property int renderableType: OpenGLInfo.renderableType +} diff --git a/tests/auto/quick/qquickopenglinfo/qquickopenglinfo.pro b/tests/auto/quick/qquickopenglinfo/qquickopenglinfo.pro new file mode 100644 index 0000000..8489dff --- /dev/null +++ b/tests/auto/quick/qquickopenglinfo/qquickopenglinfo.pro @@ -0,0 +1,15 @@ +CONFIG += testcase +TARGET = tst_qquickopenglinfo +SOURCES += tst_qquickopenglinfo.cpp + +TESTDATA = data/* +include(../../shared/util.pri) + +osx:CONFIG -= app_bundle + +CONFIG += parallel_test +QT += quick testlib + +OTHER_FILES += \ + data/basic.qml + diff --git a/tests/auto/quick/qquickopenglinfo/tst_qquickopenglinfo.cpp b/tests/auto/quick/qquickopenglinfo/tst_qquickopenglinfo.cpp new file mode 100644 index 0000000..de28769 --- /dev/null +++ b/tests/auto/quick/qquickopenglinfo/tst_qquickopenglinfo.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2014 BlackBerry Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include +#include + +#include +#include + +#include "../../shared/util.h" + +class tst_QQuickOpenGLInfo : public QQmlDataTest +{ + Q_OBJECT + +private slots: + void testProperties(); +}; + +void tst_QQuickOpenGLInfo::testProperties() +{ + QQuickView view; + view.setSource(QUrl::fromLocalFile("data/basic.qml")); + + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + QSignalSpy spy(&view, SIGNAL(sceneGraphInitialized())); + spy.wait(); + + QVERIFY(view.openglContext()); + QSurfaceFormat format = view.openglContext()->format(); + + QObject* obj = view.rootObject(); + QVERIFY(obj); + QCOMPARE(obj->property("majorVersion").toInt(), format.majorVersion()); + QCOMPARE(obj->property("minorVersion").toInt(), format.minorVersion()); + QCOMPARE(obj->property("profile").toInt(), static_cast(format.profile())); + QCOMPARE(obj->property("renderableType").toInt(), static_cast(format.renderableType())); +} + +QTEST_MAIN(tst_QQuickOpenGLInfo) + +#include "tst_qquickopenglinfo.moc" diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index 5f11da6..0a88753 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -56,6 +56,7 @@ QUICKTESTS = \ qquickloader \ qquickmousearea \ qquickmultipointtoucharea \ + qquickopenglinfo \ qquickpainteditem \ qquickpathview \ qquickpincharea \