diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2016-06-28 12:07:10 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2016-06-30 06:42:09 +0000 |
commit | b49aee19468a8f7389bd8f1ac8039b42403f8fb2 (patch) | |
tree | e38f1a3f56b4800bbadc7f8f4c0c17e181842a57 /src/quick3d/quick3dextras | |
parent | adeeb9b5301ce41ab2bfcc31e7b16b6948e1c111 (diff) |
Qt3DQuickWindow: subclass QWindow
It used to subclass QQuickWinodw which provides a QQmlIncubationController but
is hardwired to use the scenegraph and its own QOpenGLContext.
This lead to examples not working on Android and EGL based platforms as it is
more strict about multiple contexts being used on the same surface.
Instead make it subclass QWindow (which has no associated QOpenGLContext) and
implement our own QQmlIncubationController.
Change-Id: Ieb78ed517840601c804d8b222aa0c3d0118452bb
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/quick3d/quick3dextras')
-rw-r--r-- | src/quick3d/quick3dextras/qt3dquickwindow.cpp | 39 | ||||
-rw-r--r-- | src/quick3d/quick3dextras/qt3dquickwindow.h | 6 |
2 files changed, 41 insertions, 4 deletions
diff --git a/src/quick3d/quick3dextras/qt3dquickwindow.cpp b/src/quick3d/quick3dextras/qt3dquickwindow.cpp index 30348de09..10c932e98 100644 --- a/src/quick3d/quick3dextras/qt3dquickwindow.cpp +++ b/src/quick3d/quick3dextras/qt3dquickwindow.cpp @@ -59,6 +59,9 @@ #include <Qt3DLogic/qlogicaspect.h> #include <QQmlContext> +#include <qqmlincubator.h> +#include <QGuiApplication> +#include <QScreen> #include <QtGui/qopenglcontext.h> @@ -68,14 +71,39 @@ namespace Qt3DExtras { namespace Quick { +namespace { + +class Qt3DQuickWindowIncubationController : public QObject, public QQmlIncubationController +{ + Q_OBJECT +public: + explicit Qt3DQuickWindowIncubationController(QObject *parent = nullptr) + : QObject(parent) + , m_incubationTime(std::max(1, int(1000 / QGuiApplication::primaryScreen()->refreshRate()) / 3)) + { + startTimer(QGuiApplication::primaryScreen()->refreshRate()); + } + + void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE + { + incubateFor(m_incubationTime); + } + +private: + const int m_incubationTime; +}; + +} // anonymous + Qt3DQuickWindow::Qt3DQuickWindow(QWindow *parent) - : QQuickWindow(parent) + : QWindow(parent) , m_engine(nullptr) , m_renderAspect(nullptr) , m_inputAspect(nullptr) , m_logicAspect(nullptr) , m_initialized(false) , m_cameraAspectRatioMode(AutomaticAspectRatio) + , m_incubationController(nullptr) { setSurfaceType(QSurface::OpenGLSurface); @@ -163,11 +191,14 @@ void Qt3DQuickWindow::showEvent(QShowEvent *e) // Set the QQmlIncubationController on the window // to benefit from asynchronous incubation - m_engine->qmlEngine()->setIncubationController(QQuickWindow::incubationController()); + if (!m_incubationController) + m_incubationController = new Qt3DQuickWindowIncubationController(this); + + m_engine->qmlEngine()->setIncubationController(m_incubationController); m_initialized = true; } - QQuickWindow::showEvent(e); + QWindow::showEvent(e); } void Qt3DQuickWindow::onSceneCreated(QObject *rootObject) @@ -254,3 +285,5 @@ void Qt3DQuickWindow::updateCameraAspectRatio() } // Qt3DExtras QT_END_NAMESPACE + +#include "qt3dquickwindow.moc" diff --git a/src/quick3d/quick3dextras/qt3dquickwindow.h b/src/quick3d/quick3dextras/qt3dquickwindow.h index 48d2c7cb6..d278a3194 100644 --- a/src/quick3d/quick3dextras/qt3dquickwindow.h +++ b/src/quick3d/quick3dextras/qt3dquickwindow.h @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE +class QQmlIncubationController; + namespace Qt3DCore { class QAbstractAspect; namespace Quick { @@ -82,7 +84,8 @@ namespace Qt3DExtras { namespace Quick { -class QT3DQUICKEXTRASSHARED_EXPORT Qt3DQuickWindow : public QQuickWindow + +class QT3DQUICKEXTRASSHARED_EXPORT Qt3DQuickWindow : public QWindow { Q_OBJECT Q_PROPERTY(CameraAspectRatioMode cameraAspectRatioMode READ cameraAspectRatioMode WRITE setCameraAspectRatioMode NOTIFY cameraAspectRatioModeChanged) @@ -129,6 +132,7 @@ private: bool m_initialized; QPointer<Qt3DRender::QCamera> m_camera; CameraAspectRatioMode m_cameraAspectRatioMode; + QQmlIncubationController *m_incubationController; }; } // Quick |