summaryrefslogtreecommitdiffstats
path: root/src/monitor-lib/frametimer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/monitor-lib/frametimer.h')
-rw-r--r--src/monitor-lib/frametimer.h65
1 files changed, 61 insertions, 4 deletions
diff --git a/src/monitor-lib/frametimer.h b/src/monitor-lib/frametimer.h
index 17339e53..0a36a1b8 100644
--- a/src/monitor-lib/frametimer.h
+++ b/src/monitor-lib/frametimer.h
@@ -42,35 +42,92 @@
#pragma once
#include <QElapsedTimer>
+#include <QObject>
+#include <QPointer>
+#include <QTimer>
#include <QtAppManCommon/global.h>
#include <limits>
+#if defined(AM_MULTI_PROCESS)
+# include <QtWaylandCompositor/QWaylandQuickSurface>
+#endif
+
QT_BEGIN_NAMESPACE_AM
-class FrameTimer
+class FrameTimer : public QObject
{
+ Q_OBJECT
+
+ Q_PROPERTY(qreal averageFps READ averageFps NOTIFY updated)
+ Q_PROPERTY(qreal minimumFps READ minimumFps NOTIFY updated)
+ Q_PROPERTY(qreal maximumFps READ maximumFps NOTIFY updated)
+ Q_PROPERTY(qreal jitterFps READ jitterFps NOTIFY updated)
+
+ Q_PROPERTY(QObject* window READ window WRITE setWindow NOTIFY windowChanged)
+
+ Q_PROPERTY(int interval READ interval WRITE setInterval NOTIFY intervalChanged)
+ Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
+
+ Q_PROPERTY(QStringList roleNames READ roleNames CONSTANT)
public:
- FrameTimer();
+ FrameTimer(QObject *parent = nullptr);
- void newFrame();
+ QStringList roleNames() const;
- void reset();
+ Q_INVOKABLE void update();
qreal averageFps() const;
qreal minimumFps() const;
qreal maximumFps() const;
qreal jitterFps() const;
+ QObject *window() const;
+ void setWindow(QObject *value);
+
+ bool running() const;
+ void setRunning(bool value);
+
+ int interval() const;
+ void setInterval(int value);
+
+signals:
+ void updated();
+ void intervalChanged();
+ void runningChanged();
+ void windowChanged();
+
+private slots:
+ void newFrame();
+
private:
+ void reset();
+ bool connectToQuickWindow();
+ bool connectToAppManWindow();
+
+#if defined(AM_MULTI_PROCESS)
+ void disconnectFromWaylandSurface();
+ void connectToWaylandSurface();
+ QPointer<QWaylandQuickSurface> m_waylandSurface;
+#endif
+
int m_count = 0;
int m_sum = 0;
int m_min = std::numeric_limits<int>::max();
int m_max = 0;
qreal m_jitter = 0.0;
+ QPointer<QObject> m_window;
+
QElapsedTimer m_timer;
+ QTimer m_updateTimer;
+
+ qreal m_averageFps;
+ qreal m_minimumFps;
+ qreal m_maximumFps;
+ qreal m_jitterFps;
+
static const int IdealFrameTime = 16667; // usec - could be made configurable via an env variable
static const qreal MicrosInSec;
};