Skip to content
Snippets Groups Projects
Commit ec874247 authored by Pasi Keränen's avatar Pasi Keränen Committed by Miikka Heikkinen
Browse files

Adds frameTimeMs property to Canvas3D.


Adds new performance counter called frametimeMs to Canvas3D.
This counter can be used to check how much time in milliseconds the
previous frame took from signalling paintGL to glFinish returning.
This gives insight in to how much time on average frames take to render
(excluding the presenting of the frames) and how much the frame time
varies between frames.

Change-Id: I438c33207a3835d0560521960ac71ea2f60af3d9
Reviewed-by: default avatarMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>
parent ff8aa856
No related merge requests found
...@@ -94,6 +94,7 @@ Canvas::Canvas(QQuickItem *parent): ...@@ -94,6 +94,7 @@ Canvas::Canvas(QQuickItem *parent):
m_glContextShare(0), m_glContextShare(0),
m_contextWindow(0), m_contextWindow(0),
m_fps(0), m_fps(0),
m_frameTimeMs(0),
m_maxSamples(0), m_maxSamples(0),
m_devicePixelRatio(1.0f), m_devicePixelRatio(1.0f),
m_isOpenGLES2(false), m_isOpenGLES2(false),
...@@ -849,15 +850,29 @@ void Canvas::bindCurrentRenderTarget() ...@@ -849,15 +850,29 @@ void Canvas::bindCurrentRenderTarget()
} }
/*! /*!
* \qmlproperty uint Canvas3D::fps * \qmlproperty int Canvas3D::fps
* This property specifies the current frames per seconds, the value is calculated every * This property specifies the current frames per seconds, the value is calculated every
* 500 ms. * 500 ms.
* \sa frameTimeMs
*/ */
uint Canvas::fps() uint Canvas::fps()
{ {
return m_fps; return m_fps;
} }
/*!
* \qmlmethod int Canvas3D::frameTimeMs()
* This method returns the number of milliseconds the last rendered frame took to process. Before
* any frames have been rendered this method returns 0. This time is measured from the point
* the paintGL() signal was sent to the time glFinish() returns. This excludes the time it
* takes to present the frame on screen.
* \sa fps
*/
int Canvas::frameTimeMs()
{
return m_frameTimeMs;
}
/*! /*!
* \internal * \internal
*/ */
...@@ -929,6 +944,9 @@ void Canvas::renderNext() ...@@ -929,6 +944,9 @@ void Canvas::renderNext()
QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine(); QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine();
CanvasTextureImageFactory::factory(engine)->notifyLoadedImages(); CanvasTextureImageFactory::factory(engine)->notifyLoadedImages();
static QElapsedTimer frameTimer;
frameTimer.start();
// Call render in QML JavaScript side // Call render in QML JavaScript side
qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__ qCDebug(canvas3drendering).nospace() << "Canvas3D::" << __FUNCTION__
<< " Emit paintGL() signal"; << " Emit paintGL() signal";
...@@ -943,6 +961,8 @@ void Canvas::renderNext() ...@@ -943,6 +961,8 @@ void Canvas::renderNext()
glFlush(); glFlush();
glFinish(); glFinish();
m_frameTimeMs = frameTimer.elapsed();
// Update frames per second reading after glFinish() // Update frames per second reading after glFinish()
static QElapsedTimer timer; static QElapsedTimer timer;
static int frames; static int frames;
......
...@@ -102,6 +102,7 @@ public: ...@@ -102,6 +102,7 @@ public:
GLuint resolveMSAAFbo(); GLuint resolveMSAAFbo();
uint fps(); uint fps();
Q_INVOKABLE int frameTimeMs();
Q_INVOKABLE QJSValue getContext(const QString &name); Q_INVOKABLE QJSValue getContext(const QString &name);
Q_INVOKABLE QJSValue getContext(const QString &name, const QVariantMap &options); Q_INVOKABLE QJSValue getContext(const QString &name, const QVariantMap &options);
...@@ -120,6 +121,7 @@ signals: ...@@ -120,6 +121,7 @@ signals:
void contextChanged(CanvasContext *context); void contextChanged(CanvasContext *context);
void fpsChanged(uint fps); void fpsChanged(uint fps);
void pixelSizeChanged(QSize pixelSize); void pixelSizeChanged(QSize pixelSize);
void frameTimeChanged(uint frametime);
void initializeGL(); void initializeGL();
void paintGL(); void paintGL();
...@@ -153,6 +155,7 @@ private: ...@@ -153,6 +155,7 @@ private:
QQuickWindow *m_contextWindow; QQuickWindow *m_contextWindow;
uint m_fps; uint m_fps;
uint m_frameTimeMs;
int m_maxSamples; int m_maxSamples;
float m_devicePixelRatio; float m_devicePixelRatio;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment