summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire350@gmail.com>2015-06-18 19:11:31 +0200
committerSean Harmer <sean.harmer@kdab.com>2015-06-27 15:15:27 +0000
commit2f4ed37c086f1a0e2d152d3a036480c20c0a1c99 (patch)
treebe666da671630fe9776e22146684edefb9f7b96c
parent6ddbaf6258d21d5989efab1b9b6b830cf183713f (diff)
VSyncFrameAdvanceService service
Implementation of the QAbstractFrameAdvanceService for the Renderer aspect. Will allow to drive jobs using the vsync as a timer. A new logging category Qt3D.Render.VSyncAdvanceService was added specifically for debug logs from the VSyncFrameAdvanceService service. Change-Id: I81875b9ee19f73d73c7f7a244402a80b8ea0fe8a Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/backend/render-backend.pri6
-rw-r--r--src/render/backend/vsyncframeadvanceservice.cpp97
-rw-r--r--src/render/backend/vsyncframeadvanceservice_p.h70
-rw-r--r--src/render/renderlogging.cpp1
-rw-r--r--src/render/renderlogging_p.h1
5 files changed, 173 insertions, 2 deletions
diff --git a/src/render/backend/render-backend.pri b/src/render/backend/render-backend.pri
index 57b486d42..12edd63ee 100644
--- a/src/render/backend/render-backend.pri
+++ b/src/render/backend/render-backend.pri
@@ -51,7 +51,8 @@ HEADERS += \
$$PWD/platformsurfacefilter_p.h \
$$PWD/rendershaderdata_p.h \
$$PWD/renderparametermapping_p.h \
- $$PWD/rendertextureimage_p.h
+ $$PWD/rendertextureimage_p.h \
+ $$PWD/vsyncframeadvanceservice_p.h
SOURCES += \
$$PWD/qrenderaspect.cpp \
@@ -93,4 +94,5 @@ SOURCES += \
$$PWD/platformsurfacefilter.cpp \
$$PWD/rendershaderdata.cpp \
$$PWD/renderparametermapping.cpp \
- $$PWD/rendertextureimage.cpp
+ $$PWD/rendertextureimage.cpp \
+ $$PWD/vsyncframeadvanceservice.cpp
diff --git a/src/render/backend/vsyncframeadvanceservice.cpp b/src/render/backend/vsyncframeadvanceservice.cpp
new file mode 100644
index 000000000..33cf7fbae
--- /dev/null
+++ b/src/render/backend/vsyncframeadvanceservice.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** 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 "vsyncframeadvanceservice_p.h"
+#include <Qt3DRenderer/private/renderlogging_p.h>
+#include <Qt3DCore/private/qabstractframeadvanceservice_p.h>
+#include <QSemaphore>
+#include <QElapsedTimer>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Render {
+
+class VSyncFrameAdvanceServicePrivate Q_DECL_FINAL : public QAbstractFrameAdvanceServicePrivate
+{
+public:
+ VSyncFrameAdvanceServicePrivate()
+ : QAbstractFrameAdvanceServicePrivate(QStringLiteral("Renderer Aspect Frame Advance Service - aligned with vsync"))
+ , m_semaphore(0)
+ , m_elapsedTimeSincePreviousFrame(0)
+ {
+ m_elapsed.start();
+ }
+
+ QSemaphore m_semaphore;
+ QElapsedTimer m_elapsed;
+ quint64 m_elapsedTimeSincePreviousFrame;
+};
+
+VSyncFrameAdvanceService::VSyncFrameAdvanceService()
+ : QAbstractFrameAdvanceService(*new VSyncFrameAdvanceServicePrivate())
+{
+}
+
+VSyncFrameAdvanceService::~VSyncFrameAdvanceService()
+{
+}
+
+// Aspect Thread
+qint64 VSyncFrameAdvanceService::waitForNextFrame()
+{
+ Q_D(VSyncFrameAdvanceService);
+ d->m_semaphore.acquire(1);
+
+ const quint64 currentTime = d->m_elapsed.nsecsElapsed();
+ qCDebug(VSyncAdvanceService) << "Elapsed nsecs since last call " << currentTime - d->m_elapsedTimeSincePreviousFrame;
+ d->m_elapsedTimeSincePreviousFrame = currentTime;
+ return currentTime;
+}
+
+// Render Thread
+void VSyncFrameAdvanceService::proceedToNextFrame()
+{
+ Q_D(VSyncFrameAdvanceService);
+ d->m_semaphore.release(1);
+}
+
+} // Render
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/render/backend/vsyncframeadvanceservice_p.h b/src/render/backend/vsyncframeadvanceservice_p.h
new file mode 100644
index 000000000..d6356b1af
--- /dev/null
+++ b/src/render/backend/vsyncframeadvanceservice_p.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** 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_RENDER_VSYNCFRAMEADVANCESERVICE_H
+#define QT3D_RENDER_VSYNCFRAMEADVANCESERVICE_H
+
+#include <Qt3DCore/qabstractframeadvanceservice.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Render {
+
+class VSyncFrameAdvanceServicePrivate;
+
+class Q_AUTOTEST_EXPORT VSyncFrameAdvanceService Q_DECL_FINAL : public QAbstractFrameAdvanceService
+{
+public:
+ VSyncFrameAdvanceService();
+ ~VSyncFrameAdvanceService();
+
+ qint64 waitForNextFrame() Q_DECL_FINAL;
+
+ void proceedToNextFrame();
+
+private:
+ Q_DECLARE_PRIVATE(VSyncFrameAdvanceService)
+};
+
+} // Render
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_RENDER_VSYNCFRAMEADVANCESERVICE_H
diff --git a/src/render/renderlogging.cpp b/src/render/renderlogging.cpp
index c5823c6dc..780a52a53 100644
--- a/src/render/renderlogging.cpp
+++ b/src/render/renderlogging.cpp
@@ -52,6 +52,7 @@ Q_LOGGING_CATEGORY(Rendering, "Qt3D.Renderer.Rendering")
Q_LOGGING_CATEGORY(Memory, "Qt3D.Renderer.Memory")
Q_LOGGING_CATEGORY(Shaders, "Qt3D.Renderer.Shaders")
Q_LOGGING_CATEGORY(RenderStates, "Qt3D.Renderer.RenderStates")
+Q_LOGGING_CATEGORY(VSyncAdvanceService, "Qt3D.Renderer.VsyncAdvanceService")
} // Render
diff --git a/src/render/renderlogging_p.h b/src/render/renderlogging_p.h
index 494b35988..c52d5d4d4 100644
--- a/src/render/renderlogging_p.h
+++ b/src/render/renderlogging_p.h
@@ -55,6 +55,7 @@ Q_DECLARE_LOGGING_CATEGORY(Rendering)
Q_DECLARE_LOGGING_CATEGORY(Memory)
Q_DECLARE_LOGGING_CATEGORY(Shaders)
Q_DECLARE_LOGGING_CATEGORY(RenderStates)
+Q_DECLARE_LOGGING_CATEGORY(VSyncAdvanceService)
} // Render