summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2012-05-04 13:10:41 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-08 22:30:10 +0200
commitf280efc6201adf8933c9d48a1d5b6983ee9fed9b (patch)
tree8ec0d8466b951272667d6c620959d51383902630 /src/gui
parent4a58853aeae02677e6ee1a0f0ef8839578c32573 (diff)
Added QScreen::refreshRate() to get the vertical refresh rate.
To give applications that want it the option to use a fixed timestep for animations, and to avoid having values of 60 hard-coded (we have a couple of those in qtdeclarative/src/quick already), we need to know the refresh rates of the screens we are rendering to. Change-Id: Ife49162e830440ad7eab563a27e8aebbbafc5fc5 Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qguiapplication.cpp19
-rw-r--r--src/gui/kernel/qguiapplication_p.h1
-rw-r--r--src/gui/kernel/qplatformscreen.h2
-rw-r--r--src/gui/kernel/qplatformscreen_qpa.cpp11
-rw-r--r--src/gui/kernel/qscreen.cpp10
-rw-r--r--src/gui/kernel/qscreen.h4
-rw-r--r--src/gui/kernel/qscreen_p.h2
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.cpp7
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.h1
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa_p.h9
10 files changed, 66 insertions, 0 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 631592aace..62303eeea2 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1090,6 +1090,10 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
QGuiApplicationPrivate::reportLogicalDotsPerInchChange(
static_cast<QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *>(e));
break;
+ case QWindowSystemInterfacePrivate::ScreenRefreshRate:
+ QGuiApplicationPrivate::reportRefreshRateChange(
+ static_cast<QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *>(e));
+ break;
case QWindowSystemInterfacePrivate::ThemeChange:
QGuiApplicationPrivate::processThemeChanged(
static_cast<QWindowSystemInterfacePrivate::ThemeChangeEvent *>(e));
@@ -1750,6 +1754,21 @@ void QGuiApplicationPrivate::reportLogicalDotsPerInchChange(QWindowSystemInterfa
emit s->logicalDotsPerInchChanged(s->logicalDotsPerInch());
}
+void QGuiApplicationPrivate::reportRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)
+{
+ // This operation only makes sense after the QGuiApplication constructor runs
+ if (QCoreApplication::startingUp())
+ return;
+
+ if (!e->screen)
+ return;
+
+ QScreen *s = e->screen.data();
+ s->d_func()->refreshRate = e->rate;
+
+ emit s->refreshRateChanged(s->refreshRate());
+}
+
void QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e)
{
if (!e->exposed)
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index cb3587ba63..860c41d648 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -117,6 +117,7 @@ public:
static void reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
static void reportAvailableGeometryChange(QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e);
static void reportLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
+ static void reportRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h
index 075dfb114b..1743024d91 100644
--- a/src/gui/kernel/qplatformscreen.h
+++ b/src/gui/kernel/qplatformscreen.h
@@ -101,6 +101,8 @@ public:
virtual QSizeF physicalSize() const;
virtual QDpi logicalDpi() const;
+ virtual qreal refreshRate() const;
+
virtual Qt::ScreenOrientation orientation() const;
virtual QWindow *topLevelAt(const QPoint &point) const;
diff --git a/src/gui/kernel/qplatformscreen_qpa.cpp b/src/gui/kernel/qplatformscreen_qpa.cpp
index 6c2f98beb4..1fd96a80a5 100644
--- a/src/gui/kernel/qplatformscreen_qpa.cpp
+++ b/src/gui/kernel/qplatformscreen_qpa.cpp
@@ -161,6 +161,17 @@ QDpi QPlatformScreen::logicalDpi() const
}
/*!
+ Reimplement this function in subclass to return the vertical refresh rate
+ of the screen, in Hz.
+
+ The default returns 60, a sensible default for modern displays.
+*/
+qreal QPlatformScreen::refreshRate() const
+{
+ return 60;
+}
+
+/*!
Reimplement this function in subclass to return the current orientation
of the screen, for example based on accelerometer data to determine
the device orientation.
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 716caacb40..2e0df43e66 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -364,6 +364,16 @@ Qt::ScreenOrientation QScreen::orientation() const
}
/*!
+ \property QScreen::refreshRate
+ \brief the approximate vertical refresh rate of the screen in Hz
+*/
+qreal QScreen::refreshRate() const
+{
+ Q_D(const QScreen);
+ return d->refreshRate;
+}
+
+/*!
\property QScreen::primaryOrientation
\brief the primary screen orientation
diff --git a/src/gui/kernel/qscreen.h b/src/gui/kernel/qscreen.h
index f69e04a595..17f3cd3d43 100644
--- a/src/gui/kernel/qscreen.h
+++ b/src/gui/kernel/qscreen.h
@@ -83,6 +83,7 @@ class Q_GUI_EXPORT QScreen : public QObject
Q_PROPERTY(QRect availableGeometry READ availableGeometry NOTIFY availableGeometryChanged)
Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ orientation NOTIFY primaryOrientationChanged)
Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged)
+ Q_PROPERTY(qreal refreshRate READ refreshRate NOTIFY refreshRateChanged)
public:
QPlatformScreen *handle() const;
@@ -127,6 +128,8 @@ public:
QPixmap grabWindow(WId window, int x, int y, int w, int h);
+ qreal refreshRate() const;
+
Q_SIGNALS:
void sizeChanged(const QSize &size);
void geometryChanged(const QRect &geometry);
@@ -140,6 +143,7 @@ Q_SIGNALS:
void availableGeometryChanged(const QRect &rect);
void primaryOrientationChanged(Qt::ScreenOrientation orientation);
void orientationChanged(Qt::ScreenOrientation orientation);
+ void refreshRateChanged(qreal refreshRate);
private:
explicit QScreen(QPlatformScreen *screen);
diff --git a/src/gui/kernel/qscreen_p.h b/src/gui/kernel/qscreen_p.h
index 0167384b01..b0e1b8671a 100644
--- a/src/gui/kernel/qscreen_p.h
+++ b/src/gui/kernel/qscreen_p.h
@@ -63,6 +63,7 @@ public:
geometry = screen->geometry();
availableGeometry = screen->availableGeometry();
logicalDpi = screen->logicalDpi();
+ refreshRate = screen->refreshRate();
updatePrimaryOrientation();
}
@@ -74,6 +75,7 @@ public:
QRect geometry;
QRect availableGeometry;
QDpi logicalDpi;
+ qreal refreshRate;
QPlatformScreen *platformScreen;
};
diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp
index 83cf8c338c..c3136b0b0a 100644
--- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp
+++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp
@@ -434,6 +434,13 @@ void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *scree
QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
}
+void QWindowSystemInterface::handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate)
+{
+ QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e =
+ new QWindowSystemInterfacePrivate::ScreenRefreshRateEvent(screen, newRefreshRate);
+ QWindowSystemInterfacePrivate::queueWindowSystemEvent(e);
+}
+
void QWindowSystemInterface::handleThemeChange(QWindow *tlw)
{
QWindowSystemInterfacePrivate::ThemeChangeEvent *e = new QWindowSystemInterfacePrivate::ThemeChangeEvent(tlw);
diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.h b/src/gui/kernel/qwindowsysteminterface_qpa.h
index 1fbf430bf9..7e0ebf0efc 100644
--- a/src/gui/kernel/qwindowsysteminterface_qpa.h
+++ b/src/gui/kernel/qwindowsysteminterface_qpa.h
@@ -144,6 +144,7 @@ public:
static void handleScreenGeometryChange(QScreen *screen, const QRect &newGeometry);
static void handleScreenAvailableGeometryChange(QScreen *screen, const QRect &newAvailableGeometry);
static void handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal newDpiX, qreal newDpiY);
+ static void handleScreenRefreshRateChange(QScreen *screen, qreal newRefreshRate);
static void handleThemeChange(QWindow *tlw);
diff --git a/src/gui/kernel/qwindowsysteminterface_qpa_p.h b/src/gui/kernel/qwindowsysteminterface_qpa_p.h
index d7be7699e9..c7ad197b3c 100644
--- a/src/gui/kernel/qwindowsysteminterface_qpa_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_qpa_p.h
@@ -66,6 +66,7 @@ public:
ScreenGeometry,
ScreenAvailableGeometry,
ScreenLogicalDotsPerInch,
+ ScreenRefreshRate,
ThemeChange,
Expose
};
@@ -233,6 +234,14 @@ public:
qreal dpiY;
};
+ class ScreenRefreshRateEvent : public WindowSystemEvent {
+ public:
+ ScreenRefreshRateEvent(QScreen *s, qreal r)
+ : WindowSystemEvent(ScreenRefreshRate), screen(s), rate(r) { }
+ QWeakPointer<QScreen> screen;
+ qreal rate;
+ };
+
class ThemeChangeEvent : public WindowSystemEvent {
public:
explicit ThemeChangeEvent(QWindow * w)