diff options
author | Paul Lemire <paul.lemire@epitech.eu> | 2015-06-16 22:34:00 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-06-27 15:15:23 +0000 |
commit | 0f0961cffae73a0069888daf1d87e82d6f457d62 (patch) | |
tree | 813be860dbdd15178eac82defb28edd60430f654 /src/core | |
parent | b12e28a338842e273557413b235de49ec6bb04c3 (diff) |
Introduce QAbstractFrameAdvanceService and QTickClockService
This is a first step toward having aspects such as the Renderer aspect provide
a service to drive the QChangeArbiter. This is a step toward having the
QChangeArbiter synched with the vertical refresh rate
Change-Id: Ie4a98e3591e1a9ebb392e1ac4fd3dd1d213538c7
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/aspects/qaspectmanager.cpp | 28 | ||||
-rw-r--r-- | src/core/aspects/qaspectmanager_p.h | 1 | ||||
-rw-r--r-- | src/core/services/qabstractframeadvanceservice.cpp | 82 | ||||
-rw-r--r-- | src/core/services/qabstractframeadvanceservice.h | 65 | ||||
-rw-r--r-- | src/core/services/qabstractframeadvanceservice_p.h | 61 | ||||
-rw-r--r-- | src/core/services/qservicelocator.cpp | 1 | ||||
-rw-r--r-- | src/core/services/qservicelocator.h | 3 | ||||
-rw-r--r-- | src/core/services/qtickclockservice.cpp | 86 | ||||
-rw-r--r-- | src/core/services/qtickclockservice.h | 63 | ||||
-rw-r--r-- | src/core/services/services.pri | 9 |
10 files changed, 381 insertions, 18 deletions
diff --git a/src/core/aspects/qaspectmanager.cpp b/src/core/aspects/qaspectmanager.cpp index 510ea1777..d13e9c2d4 100644 --- a/src/core/aspects/qaspectmanager.cpp +++ b/src/core/aspects/qaspectmanager.cpp @@ -44,10 +44,12 @@ #include "qentity.h" #include <Qt3DCore/qservicelocator.h> +#include <Qt3DCore/qtickclockservice.h> #include <Qt3DCore/private/corelogging_p.h> #include <Qt3DCore/private/qscheduler_p.h> #include <Qt3DCore/private/qtickclock_p.h> +#include <Qt3DCore/qabstractframeadvanceservice.h> #include <QEventLoop> #include <QThread> #include <QWaitCondition> @@ -162,11 +164,7 @@ void QAspectManager::exec() // Gentlemen, start your engines QEventLoop eventLoop; - // QElapsedTimer timer; - // timer.start(); - // qint64 t(0); - QTickClock tickClock; - tickClock.start(); + QAbstractFrameAdvanceService *frameAdvanceService = Q_NULLPTR; // Enter the main loop while (!m_terminated.load()) @@ -177,14 +175,18 @@ void QAspectManager::exec() // Only enter main render loop once the renderer and other aspects are initialized while (m_runMainLoop.load()) { - // Update the clocks (just main clock for now). - // TODO: Add additional clocks - qint64 t = tickClock.waitForNextTick(); - // qDebug() << "t =" << t / 1000000; - // const qint64 t1 = timer.nsecsElapsed(); - // const qint64 dt = t1 - t; - // t = t1; - // qDebug() << "dt =" << dt; + // Retrieve the timer service that may have been overridden by one of the + // aspects + if (!frameAdvanceService) { + // Aspects such as the renderer aspect may override the tickService (vsync) + // if no aspect did register a tick service, we create a default one + if ((frameAdvanceService = m_serviceLocator->service<QAbstractFrameAdvanceService>(QServiceLocator::FrameAdvanceService)) == Q_NULLPTR) { + m_serviceLocator->registerServiceProvider(QServiceLocator::FrameAdvanceService, new QTickClockService()); + frameAdvanceService = m_serviceLocator->service<QAbstractFrameAdvanceService>(QServiceLocator::FrameAdvanceService); + } + } + + qint64 t = frameAdvanceService->waitForNextFrame(); // For each Aspect // Ask them to launch set of jobs for the current frame diff --git a/src/core/aspects/qaspectmanager_p.h b/src/core/aspects/qaspectmanager_p.h index 0e04ade93..4d072aff0 100644 --- a/src/core/aspects/qaspectmanager_p.h +++ b/src/core/aspects/qaspectmanager_p.h @@ -45,7 +45,6 @@ QT_BEGIN_NAMESPACE -class QWaitCondition; class QSurface; namespace Qt3D { diff --git a/src/core/services/qabstractframeadvanceservice.cpp b/src/core/services/qabstractframeadvanceservice.cpp new file mode 100644 index 000000000..6f438b55b --- /dev/null +++ b/src/core/services/qabstractframeadvanceservice.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Paul Lemire +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qabstractframeadvanceservice.h" +#include "qabstractframeadvanceservice_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +/*! + \class Qt3D::QAbstractFrameAdvanceServicePrivate + \internal +*/ + +/*! + \class Qt3D::QAbstractFrameAdvanceService + \inmodule Qt3DCore + \brief Interface for a Qt3D frame advance service + + This is an interface class that should be subclassed by providers of the + frame advance service. When used with the Renderer aspect, the aspect needs to + be the one providing the ticks depending on the vertical refresh rate. When + used with no Renderer aspect, a default tick clock implementation can be + used. +*/ + + +QAbstractFrameAdvanceService::QAbstractFrameAdvanceService(const QString &description) + : QAbstractServiceProvider(QServiceLocator::FrameAdvanceService, description) +{ + +} + +QAbstractFrameAdvanceService::QAbstractFrameAdvanceService(QAbstractFrameAdvanceServicePrivate &dd) + : QAbstractServiceProvider(dd) +{ + +} + +/*! + \fn qint64 Qt3D::QAbstractTickClockService::waitForNextTick() + + Returns the current time, the call may be blocking if waiting for a tick. +*/ + +} // Qt3D + +QT_END_NAMESPACE diff --git a/src/core/services/qabstractframeadvanceservice.h b/src/core/services/qabstractframeadvanceservice.h new file mode 100644 index 000000000..9bb1d6e73 --- /dev/null +++ b/src/core/services/qabstractframeadvanceservice.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Paul Lemire +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_QABSTRACTFRAMEADVANCESERVICE +#define QT3D_QABSTRACTFRAMEADVANCESERVICE + +#include <Qt3DCore/qt3dcore_global.h> +#include <Qt3DCore/qservicelocator.h> +#include <QString> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QAbstractFrameAdvanceServicePrivate; + +class QT3DCORESHARED_EXPORT QAbstractFrameAdvanceService : public QAbstractServiceProvider +{ +public: + virtual qint64 waitForNextFrame() = 0; + +protected: + QAbstractFrameAdvanceService(const QString &description = QString()); + QAbstractFrameAdvanceService(QAbstractFrameAdvanceServicePrivate &dd); +}; + +} // Qt3D + +QT_END_NAMESPACE + +#endif // QT3D_QABSTRACTFRAMEADVANCESERVICE + diff --git a/src/core/services/qabstractframeadvanceservice_p.h b/src/core/services/qabstractframeadvanceservice_p.h new file mode 100644 index 000000000..67bdd97d2 --- /dev/null +++ b/src/core/services/qabstractframeadvanceservice_p.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Paul Lemire +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_QABSTRACTFRAMEADVANCESERVICE_P_H +#define QT3D_QABSTRACTFRAMEADVANCESERVICE_P_H + +#include <Qt3DCore/qt3dcore_global.h> +#include <Qt3DCore/private/qabstractserviceprovider_p.h> +#include <Qt3DCore/qservicelocator.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QAbstractFrameAdvanceServicePrivate : public QAbstractServiceProviderPrivate +{ +public: + QAbstractFrameAdvanceServicePrivate(const QString &description) + : QAbstractServiceProviderPrivate(QServiceLocator::FrameAdvanceService, description) + {} +}; + +} + +QT_END_NAMESPACE + +#endif // QT3D_QABSTRACTFRAMEADVANCESERVICE_P_H + diff --git a/src/core/services/qservicelocator.cpp b/src/core/services/qservicelocator.cpp index 706114378..8ceb3879e 100644 --- a/src/core/services/qservicelocator.cpp +++ b/src/core/services/qservicelocator.cpp @@ -205,7 +205,6 @@ QAbstractServiceProvider *QServiceLocator::_q_getServiceHelper(int type) return systemInformation(); case OpenGLInformation: return openGLInformation(); - default: return d->m_services.value(type, Q_NULLPTR); } diff --git a/src/core/services/qservicelocator.h b/src/core/services/qservicelocator.h index ab8ddb413..4f234892f 100644 --- a/src/core/services/qservicelocator.h +++ b/src/core/services/qservicelocator.h @@ -80,7 +80,8 @@ public: #if !defined(Q_QDOC) DefaultServiceCount, // Add additional default services before here #endif - UserService = 256 + FrameAdvanceService, + UserService = 256, }; void registerServiceProvider(int serviceType, QAbstractServiceProvider *provider); diff --git a/src/core/services/qtickclockservice.cpp b/src/core/services/qtickclockservice.cpp new file mode 100644 index 000000000..c23c33cb5 --- /dev/null +++ b/src/core/services/qtickclockservice.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Paul Lemire +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtickclockservice.h" +#include "qtickclock_p.h" +#include "qabstractframeadvanceservice_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3D { +/*! + \class Qt3D::QTickClockServicePrivate + \internal +*/ + +class QTickClockServicePrivate : public QAbstractFrameAdvanceServicePrivate +{ +public: + QTickClockServicePrivate() + : QAbstractFrameAdvanceServicePrivate(QStringLiteral("Default Frame Advance Service implementation")) + { + m_clock.setTickFrequency(60); + m_clock.start(); + } + + QTickClock m_clock; +}; + +/*! + \class Qt3D::QTickClockService + \inmodule Qt3DCore + \brief Default Qt3D::QAbstractFrameAdvanceService implementation. + + This default Qt3D::QAbstractFrameAdvanceService implementation has a frequency of 60 Hz. +*/ +QTickClockService::QTickClockService() + : QAbstractFrameAdvanceService(*new QTickClockServicePrivate()) +{ +} + +QTickClockService::~QTickClockService() +{ +} + +qint64 QTickClockService::waitForNextFrame() +{ + Q_D(QTickClockService); + return d->m_clock.waitForNextTick(); +} + +} // Qt3D + +QT_END_NAMESPACE diff --git a/src/core/services/qtickclockservice.h b/src/core/services/qtickclockservice.h new file mode 100644 index 000000000..59adee9a1 --- /dev/null +++ b/src/core/services/qtickclockservice.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Paul Lemire +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_QTICKCLOCKSERVICE_H +#define QT3D_QTICKCLOCKSERVICE_H + +#include "qabstractframeadvanceservice.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QTickClockServicePrivate; + +class QTickClockService : public QAbstractFrameAdvanceService +{ +public: + QTickClockService(); + ~QTickClockService(); + + qint64 waitForNextFrame() Q_DECL_FINAL; + + Q_DECLARE_PRIVATE(QTickClockService) +}; + +} // Qt3D + +QT_END_NAMESPACE + +#endif // QT3D_QTICKCLOCKSERVICE_H diff --git a/src/core/services/services.pri b/src/core/services/services.pri index 547ec6d32..370f3c2d6 100644 --- a/src/core/services/services.pri +++ b/src/core/services/services.pri @@ -2,7 +2,9 @@ SOURCES += \ $$PWD/qservicelocator.cpp \ $$PWD/qsysteminformationservice.cpp \ - $$PWD/qopenglinformationservice.cpp + $$PWD/qopenglinformationservice.cpp \ + $$PWD/qtickclockservice.cpp \ + $$PWD/qabstractframeadvanceservice.cpp HEADERS += \ $$PWD/qservicelocator.h \ @@ -11,6 +13,9 @@ HEADERS += \ $$PWD/qopenglinformationservice.h \ $$PWD/qabstractserviceprovider_p.h \ $$PWD/qsysteminformationservice_p.h \ - $$PWD/qopenglinformationservice_p.h + $$PWD/qopenglinformationservice_p.h \ + $$PWD/qtickclockservice.h \ + $$PWD/qabstractframeadvanceservice.h \ + $$PWD/qabstractframeadvanceservice_p.h INCLUDEPATH += $$PWD |