diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-03-17 11:03:06 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2011-03-17 16:48:03 (GMT) |
commit | 5e2f4be486140d694c0acccbfc7a55fc7c104c61 (patch) | |
tree | b1d1741fa10ec065cd1f21ee83b1520886f56951 | |
parent | 2ba58fc0a36a30d19e46f9c012598958f98c2e33 (diff) | |
download | Qt-5e2f4be486140d694c0acccbfc7a55fc7c104c61.zip Qt-5e2f4be486140d694c0acccbfc7a55fc7c104c61.tar.gz Qt-5e2f4be486140d694c0acccbfc7a55fc7c104c61.tar.bz2 |
Switch to raster also when last window is destroyed (on MeeGo).
This will save GPU resources for applications that are in the
background for most of the time and only show a window now and then.
Reviewed-by: Armin Berres
-rw-r--r-- | src/plugins/graphicssystems/meego/qmeegographicssystem.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp b/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp index 18a0944..cb66695 100644 --- a/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp +++ b/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp @@ -59,6 +59,8 @@ #include "qmeegographicssystem.h" #include "qmeegoextensions.h" +#include <QTimer> + bool QMeeGoGraphicsSystem::surfaceWasCreated = false; QHash <Qt::HANDLE, QPixmap*> QMeeGoGraphicsSystem::liveTexturePixmaps; @@ -85,8 +87,12 @@ public: void addWidget(QWidget *widget); bool eventFilter(QObject *, QEvent *); + void handleMapNotify(); + private slots: void removeWidget(QObject *object); + void switchToRaster(); + void switchToMeeGo(); private: int visibleWidgets() const; @@ -95,22 +101,46 @@ private: QList<QWidget *> m_widgets; }; +typedef bool(*QX11FilterFunction)(XEvent *event); +Q_GUI_EXPORT void qt_installX11EventFilter(QX11FilterFunction func); + +static bool x11EventFilter(XEvent *event); + QMeeGoGraphicsSystemSwitchHandler::QMeeGoGraphicsSystemSwitchHandler() { + qt_installX11EventFilter(x11EventFilter); } void QMeeGoGraphicsSystemSwitchHandler::addWidget(QWidget *widget) { - if (!m_widgets.contains(widget)) { + if (widget != qt_gl_share_widget() && !m_widgets.contains(widget)) { widget->installEventFilter(this); connect(widget, SIGNAL(destroyed(QObject *)), this, SLOT(removeWidget(QObject *))); m_widgets << widget; } } +void QMeeGoGraphicsSystemSwitchHandler::handleMapNotify() +{ + if (m_widgets.isEmpty()) + QTimer::singleShot(0, this, SLOT(switchToMeeGo())); +} + void QMeeGoGraphicsSystemSwitchHandler::removeWidget(QObject *object) { m_widgets.removeOne(static_cast<QWidget *>(object)); + if (m_widgets.isEmpty()) + QTimer::singleShot(0, this, SLOT(switchToRaster())); +} + +void QMeeGoGraphicsSystemSwitchHandler::switchToRaster() +{ + QMeeGoGraphicsSystem::switchToRaster(); +} + +void QMeeGoGraphicsSystemSwitchHandler::switchToMeeGo() +{ + QMeeGoGraphicsSystem::switchToMeeGo(); } int QMeeGoGraphicsSystemSwitchHandler::visibleWidgets() const @@ -148,6 +178,13 @@ bool QMeeGoGraphicsSystemSwitchHandler::eventFilter(QObject *object, QEvent *eve Q_GLOBAL_STATIC(QMeeGoGraphicsSystemSwitchHandler, switch_handler) +bool x11EventFilter(XEvent *event) +{ + if (event->type == MapNotify) + switch_handler()->handleMapNotify(); + return false; +} + QWindowSurface* QMeeGoGraphicsSystem::createWindowSurface(QWidget *widget) const { QGLWidget *shareWidget = qt_gl_share_widget(); |