From 739a36b3e86d6c112bc1720ec92a61433c48ee80 Mon Sep 17 00:00:00 2001
From: Anders Bakken <anders.bakken@nokia.com>
Date: Thu, 15 Oct 2009 08:15:34 -0700
Subject: Fix a problem with QDirectFBScreen::instance

If using a proxy screen QScreen::instance() will not return a
QDirectFBScreen but rather a QProxyScreen. This patch lets
QDirectFBScreen::instance hold its own pointer.

Reviewed-by: Jervey Kong <jervey.kong@nokia.com>
---
 src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp | 11 +++++++++++
 src/plugins/gfxdrivers/directfb/qdirectfbscreen.h   |  7 +------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
index 0f7a6de..00eeebd 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
@@ -99,8 +99,11 @@ public:
     qint64 cursorImageKey;
 
     QDirectFBScreen *q;
+    static QDirectFBScreen *instance;
 };
 
+QDirectFBScreen *QDirectFBScreenPrivate::instance = 0;
+
 QDirectFBScreenPrivate::QDirectFBScreenPrivate(QDirectFBScreen *qptr)
     : QWSGraphicsSystem(qptr), dfb(0), flipFlags(DSFLIP_NONE),
       directFBFlags(QDirectFBScreen::NoFlags), alphaPixmapFormat(QImage::Format_Invalid),
@@ -802,13 +805,21 @@ void QDirectFBScreenCursor::set(const QImage &image, int hotx, int hoty)
 QDirectFBScreen::QDirectFBScreen(int display_id)
     : QScreen(display_id, DirectFBClass), d_ptr(new QDirectFBScreenPrivate(this))
 {
+    QDirectFBScreenPrivate::instance = this;
 }
 
 QDirectFBScreen::~QDirectFBScreen()
 {
+    if (QDirectFBScreenPrivate::instance == this)
+        QDirectFBScreenPrivate::instance = 0;
     delete d_ptr;
 }
 
+QDirectFBScreen *QDirectFBScreen::instance()
+{
+    return QDirectFBScreenPrivate::instance;
+}
+
 int QDirectFBScreen::depth(DFBSurfacePixelFormat format)
 {
     switch (format) {
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
index 5e8c5c6..437f1ae 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
@@ -163,12 +163,7 @@ public:
     QWSWindowSurface *createSurface(QWidget *widget) const;
     QWSWindowSurface *createSurface(const QString &key) const;
 
-    static inline QDirectFBScreen *instance() {
-        QScreen *inst = QScreen::instance();
-        Q_ASSERT(!inst || inst->classId() == QScreen::DirectFBClass);
-        return static_cast<QDirectFBScreen*>(inst);
-    }
-
+    static QDirectFBScreen *instance();
     void waitIdle();
     IDirectFBSurface *surfaceForWidget(const QWidget *widget, QRect *rect) const;
 #ifdef QT_DIRECTFB_SUBSURFACE
-- 
cgit v0.12