summaryrefslogtreecommitdiffstats
path: root/src/plugins/graphicssystems
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-03-10 11:03:45 (GMT)
committerSamuel Rødal <samuel.rodal@nokia.com>2011-03-16 07:17:15 (GMT)
commit7c99a5273bea6f071efcd8441bedc1b768cc1d7a (patch)
treee479d99c429ecd4e89e84887ef6b227b846e4375 /src/plugins/graphicssystems
parentf4244785cb8875b177274db485a346605f05ed7c (diff)
downloadQt-7c99a5273bea6f071efcd8441bedc1b768cc1d7a.zip
Qt-7c99a5273bea6f071efcd8441bedc1b768cc1d7a.tar.gz
Qt-7c99a5273bea6f071efcd8441bedc1b768cc1d7a.tar.bz2
Added automatic graphicssystem switching on meego when app is minimized.
When all top-level widgets are minimized we switch to raster to reduce GPU memory consumption. We switch back to graphicssystem meego when at least one top-level widget is shown normally again. The switching only applies when the runtime graphicssystem is being used. The switching only applies when the runtime graphicssystem is being used. Task-number: QTBUG-18013 Reviewed-by: Armin Berres
Diffstat (limited to 'src/plugins/graphicssystems')
-rw-r--r--src/plugins/graphicssystems/meego/qmeegographicssystem.cpp170
-rw-r--r--src/plugins/graphicssystems/meego/qmeegographicssystem.h18
2 files changed, 174 insertions, 14 deletions
diff --git a/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp b/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp
index 13eab7f..18a0944 100644
--- a/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp
+++ b/src/plugins/graphicssystems/meego/qmeegographicssystem.cpp
@@ -63,6 +63,8 @@ bool QMeeGoGraphicsSystem::surfaceWasCreated = false;
QHash <Qt::HANDLE, QPixmap*> QMeeGoGraphicsSystem::liveTexturePixmaps;
+QList<QMeeGoSwitchCallback> QMeeGoGraphicsSystem::switchCallbacks;
+
QMeeGoGraphicsSystem::QMeeGoGraphicsSystem()
{
qDebug("Using the meego graphics system");
@@ -74,6 +76,78 @@ QMeeGoGraphicsSystem::~QMeeGoGraphicsSystem()
qt_destroy_gl_share_widget();
}
+class QMeeGoGraphicsSystemSwitchHandler : public QObject
+{
+ Q_OBJECT
+public:
+ QMeeGoGraphicsSystemSwitchHandler();
+
+ void addWidget(QWidget *widget);
+ bool eventFilter(QObject *, QEvent *);
+
+private slots:
+ void removeWidget(QObject *object);
+
+private:
+ int visibleWidgets() const;
+
+private:
+ QList<QWidget *> m_widgets;
+};
+
+QMeeGoGraphicsSystemSwitchHandler::QMeeGoGraphicsSystemSwitchHandler()
+{
+}
+
+void QMeeGoGraphicsSystemSwitchHandler::addWidget(QWidget *widget)
+{
+ if (!m_widgets.contains(widget)) {
+ widget->installEventFilter(this);
+ connect(widget, SIGNAL(destroyed(QObject *)), this, SLOT(removeWidget(QObject *)));
+ m_widgets << widget;
+ }
+}
+
+void QMeeGoGraphicsSystemSwitchHandler::removeWidget(QObject *object)
+{
+ m_widgets.removeOne(static_cast<QWidget *>(object));
+}
+
+int QMeeGoGraphicsSystemSwitchHandler::visibleWidgets() const
+{
+ int count = 0;
+ for (int i = 0; i < m_widgets.size(); ++i)
+ count += m_widgets.at(i)->isVisible() && !(m_widgets.at(i)->windowState() & Qt::WindowMinimized);
+ return count;
+}
+
+bool QMeeGoGraphicsSystemSwitchHandler::eventFilter(QObject *object, QEvent *event)
+{
+ if (event->type() == QEvent::WindowStateChange) {
+ QWindowStateChangeEvent *change = static_cast<QWindowStateChangeEvent *>(event);
+ QWidget *widget = static_cast<QWidget *>(object);
+
+ Qt::WindowStates current = widget->windowState();
+ Qt::WindowStates old = change->oldState();
+
+ // did minimized flag change?
+ if ((current ^ old) & Qt::WindowMinimized) {
+ if (current & Qt::WindowMinimized) {
+ if (visibleWidgets() == 0)
+ QMeeGoGraphicsSystem::switchToRaster();
+ } else {
+ if (visibleWidgets() == 1)
+ QMeeGoGraphicsSystem::switchToMeeGo();
+ }
+ }
+ }
+
+ // resume processing of event
+ return false;
+}
+
+Q_GLOBAL_STATIC(QMeeGoGraphicsSystemSwitchHandler, switch_handler)
+
QWindowSurface* QMeeGoGraphicsSystem::createWindowSurface(QWidget *widget) const
{
QGLWidget *shareWidget = qt_gl_share_widget();
@@ -83,6 +157,9 @@ QWindowSurface* QMeeGoGraphicsSystem::createWindowSurface(QWidget *widget) const
QGLShareContextScope ctx(shareWidget->context());
+ if (QApplicationPrivate::instance()->graphics_system_name == QLatin1String("runtime"))
+ switch_handler()->addWidget(widget);
+
QMeeGoGraphicsSystem::surfaceWasCreated = true;
QWindowSurface *surface = new QGLWindowSurface(widget);
return surface;
@@ -203,18 +280,7 @@ QPixmapData *QMeeGoGraphicsSystem::pixmapDataWithGLTexture(int w, int h)
bool QMeeGoGraphicsSystem::meeGoRunning()
{
- if (! QApplicationPrivate::instance()) {
- qWarning("Application not running just yet... hard to know what system running!");
- return false;
- }
-
- QString name = QApplicationPrivate::instance()->graphics_system_name;
- if (name == "runtime") {
- QRuntimeGraphicsSystem *rsystem = (QRuntimeGraphicsSystem *) QApplicationPrivate::instance()->graphics_system;
- name = rsystem->graphicsSystemName();
- }
-
- return (name == "meego");
+ return runningGraphicsSystemName() == "meego";
}
QPixmapData* QMeeGoGraphicsSystem::pixmapDataWithNewLiveTexture(int w, int h, QImage::Format format)
@@ -259,6 +325,69 @@ void QMeeGoGraphicsSystem::destroyFenceSync(void *fenceSync)
QMeeGoExtensions::eglDestroySyncKHR(QEgl::display(), fenceSync);
}
+QString QMeeGoGraphicsSystem::runningGraphicsSystemName()
+{
+ if (!QApplicationPrivate::instance()) {
+ qWarning("Querying graphics system but application not running yet!");
+ return QString();
+ }
+
+ QString name = QApplicationPrivate::instance()->graphics_system_name;
+ if (name == QLatin1String("runtime")) {
+ QRuntimeGraphicsSystem *rsystem = (QRuntimeGraphicsSystem *) QApplicationPrivate::instance()->graphics_system;
+ name = rsystem->graphicsSystemName();
+ }
+
+ return name;
+}
+
+void QMeeGoGraphicsSystem::switchToMeeGo()
+{
+ if (meeGoRunning())
+ return;
+
+ if (QApplicationPrivate::instance()->graphics_system_name != QLatin1String("runtime"))
+ qWarning("Can't switch to meego - switching only supported with 'runtime' graphics system.");
+ else {
+ triggerSwitchCallbacks(0, "meego");
+
+ QApplication *app = static_cast<QApplication *>(QCoreApplication::instance());
+ app->setGraphicsSystem(QLatin1String("meego"));
+
+ triggerSwitchCallbacks(1, "meego");
+ }
+}
+
+void QMeeGoGraphicsSystem::switchToRaster()
+{
+ if (runningGraphicsSystemName() == QLatin1String("raster"))
+ return;
+
+ if (QApplicationPrivate::instance()->graphics_system_name != QLatin1String("runtime"))
+ qWarning("Can't switch to raster - switching only supported with 'runtime' graphics system.");
+ else {
+ triggerSwitchCallbacks(0, "raster");
+
+ QApplication *app = static_cast<QApplication *>(QCoreApplication::instance());
+ app->setGraphicsSystem(QLatin1String("raster"));
+
+ QMeeGoLivePixmapData::invalidateSurfaces();
+
+ triggerSwitchCallbacks(1, "raster");
+ }
+}
+
+void QMeeGoGraphicsSystem::registerSwitchCallback(QMeeGoSwitchCallback callback)
+{
+ switchCallbacks << callback;
+}
+
+void QMeeGoGraphicsSystem::triggerSwitchCallbacks(int type, const char *name)
+{
+ for (int i = 0; i < switchCallbacks.size(); ++i)
+ switchCallbacks.at(i)(type, name);
+}
+
/* C API */
int qt_meego_image_to_egl_shared_image(const QImage &image)
@@ -340,3 +469,20 @@ void qt_meego_invalidate_live_surfaces(void)
{
return QMeeGoLivePixmapData::invalidateSurfaces();
}
+
+void qt_meego_switch_to_raster(void)
+{
+ QMeeGoGraphicsSystem::switchToRaster();
+}
+
+void qt_meego_switch_to_meego(void)
+{
+ QMeeGoGraphicsSystem::switchToMeeGo();
+}
+
+void qt_meego_register_switch_callback(QMeeGoSwitchCallback callback)
+{
+ QMeeGoGraphicsSystem::registerSwitchCallback(callback);
+}
+
+#include "qmeegographicssystem.moc"
diff --git a/src/plugins/graphicssystems/meego/qmeegographicssystem.h b/src/plugins/graphicssystems/meego/qmeegographicssystem.h
index 27a4e7a..ecc85b2 100644
--- a/src/plugins/graphicssystems/meego/qmeegographicssystem.h
+++ b/src/plugins/graphicssystems/meego/qmeegographicssystem.h
@@ -47,6 +47,8 @@
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
+extern "C" typedef void (*QMeeGoSwitchCallback)(int type, const char *name);
+
class QMeeGoGraphicsSystem : public QGraphicsSystem
{
public:
@@ -76,13 +78,22 @@ public:
static void* createFenceSync();
static void destroyFenceSync(void* fenceSync);
+ static void switchToRaster();
+ static void switchToMeeGo();
+ static QString runningGraphicsSystemName();
+
+ static void registerSwitchCallback(QMeeGoSwitchCallback callback);
+
private:
static bool meeGoRunning();
static EGLSurface getSurfaceForLiveTexturePixmap(QPixmap *pixmap);
static void destroySurfaceForLiveTexturePixmap(QPixmapData* pmd);
+ static void triggerSwitchCallbacks(int type, const char *name);
static bool surfaceWasCreated;
- static QHash <Qt::HANDLE, QPixmap*> liveTexturePixmaps;
+ static QHash<Qt::HANDLE, QPixmap*> liveTexturePixmaps;
+ static QList<QMeeGoSwitchCallback> switchCallbacks;
+
};
/* C api */
@@ -95,7 +106,7 @@ extern "C" {
Q_DECL_EXPORT bool qt_meego_destroy_egl_shared_image(Qt::HANDLE handle);
Q_DECL_EXPORT void qt_meego_set_surface_fixed_size(int width, int height);
Q_DECL_EXPORT void qt_meego_set_surface_scaling(int x, int y, int width, int height);
- Q_DECL_EXPORT void qt_meego_set_translucent(bool translucent);
+ Q_DECL_EXPORT void qt_meego_set_translucent(bool translucent);
Q_DECL_EXPORT QPixmapData* qt_meego_pixmapdata_with_new_live_texture(int w, int h, QImage::Format format);
Q_DECL_EXPORT QPixmapData* qt_meego_pixmapdata_from_live_texture_handle(Qt::HANDLE handle);
Q_DECL_EXPORT QImage* qt_meego_live_texture_lock(QPixmap *pixmap, void *fenceSync);
@@ -104,6 +115,9 @@ extern "C" {
Q_DECL_EXPORT void* qt_meego_create_fence_sync(void);
Q_DECL_EXPORT void qt_meego_destroy_fence_sync(void* fs);
Q_DECL_EXPORT void qt_meego_invalidate_live_surfaces(void);
+ Q_DECL_EXPORT void qt_meego_switch_to_raster(void);
+ Q_DECL_EXPORT void qt_meego_switch_to_meego(void);
+ Q_DECL_EXPORT void qt_meego_register_switch_callback(QMeeGoSwitchCallback callback);
}
#endif