aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Berres <armin.berres@basyskom.de>2010-08-30 16:20:57 +0200
committerSergiy Dubovik <sergiy.dubovik@nokia.com>2010-09-07 14:04:58 +0300
commitcbeed778588f1cde1b9835122c3e1f5e7418e4eb (patch)
treec42737fc92d3c55d5be735f31151df2abf29f550
parent03849c6c584e3faf27e6e5db363aa0947443e9aa (diff)
Changes: limit rendering of minimized applications to 5fps
RevBy: Stanislav, Michael Hasselmann Changes: Minimized applications are not allowed to repaint more than 5 times per second. All paint events when beeing in the switcher and invisible will be discarded. The base is there to disable paiting completely also for invisible foreground applications. It is not yet actived though as it would eat the very first frames when an application is started.
-rw-r--r--src/corelib/widgets/mwindow.cpp44
-rw-r--r--src/corelib/widgets/mwindow_p.h5
2 files changed, 48 insertions, 1 deletions
diff --git a/src/corelib/widgets/mwindow.cpp b/src/corelib/widgets/mwindow.cpp
index 3f4c69f5..31cfd34e 100644
--- a/src/corelib/widgets/mwindow.cpp
+++ b/src/corelib/widgets/mwindow.cpp
@@ -76,6 +76,8 @@ MWindowPrivate::MWindowPrivate() :
minimizedSoftwareSwitchItem("/meegotouch/debug/minimized_software_switch"),
#endif
minimizedSoftwareSwitch(false),
+ updateIsPending(false),
+ discardedPaintEvent(false),
q_ptr(NULL)
{
#ifndef Q_WS_X11
@@ -88,6 +90,8 @@ MWindowPrivate::MWindowPrivate() :
angle = window->orientationAngle();
else
angle = MOrientationTracker::instance()->orientationAngle();
+
+ timeSinceLastPaintInSwitcher.invalidate();
}
MWindowPrivate::~MWindowPrivate()
@@ -386,6 +390,13 @@ void MWindowPrivate::doEnterDisplayEvent()
q->enterDisplayEvent();
emit q->displayEntered();
+
+ if (discardedPaintEvent) {
+ // we discarded a paint event while beeing invisible
+ // make sure the screen is up to date
+ discardedPaintEvent = false;
+ QTimer::singleShot(0, q->viewport(), SLOT(update()));
+ }
}
void MWindowPrivate::doExitDisplayEvent()
@@ -442,6 +453,7 @@ void MWindowPrivate::windowStateChangeEvent(QWindowStateChangeEvent *event)
else if (event->oldState() == Qt::WindowMinimized &&
q->windowState() != Qt::WindowMinimized) {
isInSwitcher = false;
+ timeSinceLastPaintInSwitcher.invalidate();
emit q->switcherExited();
}
@@ -943,14 +955,44 @@ void MWindow::onDisplayChangeEvent(MOnDisplayChangeEvent *event)
void MWindow::paintEvent(QPaintEvent *event)
{
-#ifdef M_USE_OPENGL
Q_D(MWindow);
+#ifdef M_USE_OPENGL
if (!MApplication::softwareRendering()) {
MGLES2Renderer::activate(d->glWidget);
}
#endif // M_USE_OPENGL
+ if (isInSwitcher()) {
+ if (!isOnDisplay()) {
+ // TODO: also do this check for the foreground app not visible in the switcher once onDisplay is immediately
+ // true when starting an application. right now during startup the first frames would be discarded
+ mWarning("MWindow::paintEvent") << "Application is not visible. Paint event discarded. Make sure the application does not paint in the first place.";
+ event->accept();
+ d->discardedPaintEvent = true;
+ return;
+ } else if (!d->timeSinceLastPaintInSwitcher.isValid()) {
+ d->timeSinceLastPaintInSwitcher.start();
+ d->updateIsPending = false;
+ } else {
+ const int maxFpsInSwitcher = 5;
+ const int minDelay = 1000. / maxFpsInSwitcher;
+ qint64 msSinceLastPaint = d->timeSinceLastPaintInSwitcher.elapsed();
+ if (msSinceLastPaint < minDelay) {
+ event->accept();
+ if (!d->updateIsPending) {
+ // trigger a new paint event as otherwise the screen may not be up to date
+ QTimer::singleShot(minDelay, viewport(), SLOT(update()));
+ d->updateIsPending = true;
+ }
+ return;
+ } else {
+ d->timeSinceLastPaintInSwitcher.restart();
+ d->updateIsPending = false;
+ }
+ }
+ }
+
QGraphicsView::paintEvent(event);
}
diff --git a/src/corelib/widgets/mwindow_p.h b/src/corelib/widgets/mwindow_p.h
index 7e190d10..eaa04e36 100644
--- a/src/corelib/widgets/mwindow_p.h
+++ b/src/corelib/widgets/mwindow_p.h
@@ -21,6 +21,7 @@
#define MWINDOW_P_H
#include <QTimeLine>
+#include <QElapsedTimer>
#include "mwindow.h"
#include <mscenemanager.h>
@@ -98,6 +99,10 @@ public:
#endif
bool minimizedSoftwareSwitch;
+ QElapsedTimer timeSinceLastPaintInSwitcher;
+ bool updateIsPending;
+ bool discardedPaintEvent;
+
protected:
MWindow *q_ptr;
private: