Remove static methods in QQnxScreen

Change-Id: If0fd910848ba70d3b0a2d948065b09337f8e51c3
Reviewed-by: Kevin Krammer <kevin.krammer@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
This commit is contained in:
Thomas McGuire 2012-03-29 15:23:57 +02:00 committed by Qt by Nokia
parent 5d7f7e6559
commit b5f343b367
6 changed files with 130 additions and 110 deletions

View File

@ -100,10 +100,7 @@ QQnxIntegration::QQnxIntegration()
} }
// Create displays for all possible screens (which may not be attached) // Create displays for all possible screens (which may not be attached)
QQnxScreen::createDisplays(m_screenContext); createDisplays();
Q_FOREACH (QPlatformScreen *screen, QQnxScreen::screens()) {
screenAdded(screen);
}
// Initialize global OpenGL resources // Initialize global OpenGL resources
QQnxGLContext::initialize(); QQnxGLContext::initialize();
@ -115,7 +112,7 @@ QQnxIntegration::QQnxIntegration()
// Create/start navigator event handler // Create/start navigator event handler
// Not on BlackBerry, it has specialised event dispatcher which also handles navigator events // Not on BlackBerry, it has specialised event dispatcher which also handles navigator events
#ifndef Q_OS_BLACKBERRY #ifndef Q_OS_BLACKBERRY
m_navigatorEventHandler = new QQnxNavigatorEventHandler(*QQnxScreen::primaryDisplay()); m_navigatorEventHandler = new QQnxNavigatorEventHandler(*primaryDisplay());
// delay invocation of start() to the time the event loop is up and running // delay invocation of start() to the time the event loop is up and running
// needed to have the QThread internals of the main thread properly initialized // needed to have the QThread internals of the main thread properly initialized
@ -131,7 +128,7 @@ QQnxIntegration::QQnxIntegration()
// TODO check if we need to do this for all screens or only the primary one // TODO check if we need to do this for all screens or only the primary one
QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(int)), QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(int)),
QQnxScreen::primaryDisplay(), SLOT(keyboardHeightChanged(int))); primaryDisplay(), SLOT(keyboardHeightChanged(int)));
// Set up the input context // Set up the input context
m_inputContext = new QQnxInputContext(*m_virtualKeyboard); m_inputContext = new QQnxInputContext(*m_virtualKeyboard);
@ -166,7 +163,7 @@ QQnxIntegration::~QQnxIntegration()
delete m_navigatorEventHandler; delete m_navigatorEventHandler;
// Destroy all displays // Destroy all displays
QQnxScreen::destroyDisplays(); destroyDisplays();
// Close connection to QNX composition manager // Close connection to QNX composition manager
screen_destroy_context(m_screenContext); screen_destroy_context(m_screenContext);
@ -204,7 +201,6 @@ QPlatformWindow *QQnxIntegration::createPlatformWindow(QWindow *window) const
#if defined(QQNXINTEGRATION_DEBUG) #if defined(QQNXINTEGRATION_DEBUG)
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
#endif #endif
// New windows are created on the primary display.
return new QQnxWindow(window, m_screenContext); return new QQnxWindow(window, m_screenContext);
} }
@ -245,20 +241,12 @@ void QQnxIntegration::moveToScreen(QWindow *window, int screen)
QQnxWindow *platformWindow = static_cast<QQnxWindow *>(window->handle()); QQnxWindow *platformWindow = static_cast<QQnxWindow *>(window->handle());
// lookup platform screen by index // lookup platform screen by index
QQnxScreen *platformScreen = static_cast<QQnxScreen*>(QQnxScreen::screens().at(screen)); QQnxScreen *platformScreen = m_screens.at(screen);
// move the platform window to the platform screen // move the platform window to the platform screen
platformWindow->setScreen(platformScreen); platformWindow->setScreen(platformScreen);
} }
QList<QPlatformScreen *> QQnxIntegration::screens() const
{
#if defined(QQNXINTEGRATION_DEBUG)
qDebug() << Q_FUNC_INFO;
#endif
return QQnxScreen::screens();
}
QAbstractEventDispatcher *QQnxIntegration::guiThreadEventDispatcher() const QAbstractEventDispatcher *QQnxIntegration::guiThreadEventDispatcher() const
{ {
#if defined(QQNXINTEGRATION_DEBUG) #if defined(QQNXINTEGRATION_DEBUG)
@ -326,4 +314,49 @@ void QQnxIntegration::removeWindow(screen_window_t qnxWindow)
ms_windowMapper.remove(qnxWindow); ms_windowMapper.remove(qnxWindow);
} }
void QQnxIntegration::createDisplays()
{
#if defined(QQNXINTEGRATION_DEBUG)
qDebug() << Q_FUNC_INFO;
#endif
// Query number of displays
errno = 0;
int displayCount;
int result = screen_get_context_property_iv(m_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &displayCount);
if (result != 0) {
qFatal("QQnxIntegration: failed to query display count, errno=%d", errno);
}
// Get all displays
errno = 0;
screen_display_t *displays = (screen_display_t *)alloca(sizeof(screen_display_t) * displayCount);
result = screen_get_context_property_pv(m_screenContext, SCREEN_PROPERTY_DISPLAYS, (void **)displays);
if (result != 0) {
qFatal("QQnxIntegration: failed to query displays, errno=%d", errno);
}
for (int i=0; i<displayCount; i++) {
#if defined(QQNXINTEGRATION_DEBUG)
qDebug() << "QQnxIntegration::Creating screen for display " << i;
#endif
QQnxScreen *screen = new QQnxScreen(m_screenContext, displays[i], i==0);
m_screens.append(screen);
screenAdded(screen);
}
}
void QQnxIntegration::destroyDisplays()
{
#if defined(QQNXINTEGRATION_DEBUG)
qDebug() << Q_FUNC_INFO;
#endif
qDeleteAll(m_screens);
m_screens.clear();
}
QQnxScreen *QQnxIntegration::primaryDisplay() const
{
return m_screens.first();
}
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -56,6 +56,7 @@ class QQnxNavigatorEventHandler;
class QQnxAbstractVirtualKeyboard; class QQnxAbstractVirtualKeyboard;
class QQnxWindow; class QQnxWindow;
class QQnxServices; class QQnxServices;
class QQnxScreen;
#ifndef QT_NO_CLIPBOARD #ifndef QT_NO_CLIPBOARD
class QQnxClipboard; class QQnxClipboard;
@ -78,7 +79,6 @@ public:
QPlatformInputContext *inputContext() const; QPlatformInputContext *inputContext() const;
QList<QPlatformScreen *> screens() const;
void moveToScreen(QWindow *window, int screen); void moveToScreen(QWindow *window, int screen);
QAbstractEventDispatcher *guiThreadEventDispatcher() const; QAbstractEventDispatcher *guiThreadEventDispatcher() const;
@ -98,6 +98,10 @@ public:
static QWindow *window(screen_window_t qnxWindow); static QWindow *window(screen_window_t qnxWindow);
private: private:
void createDisplays();
void destroyDisplays();
QQnxScreen *primaryDisplay() const;
static void addWindow(screen_window_t qnxWindow, QWindow *window); static void addWindow(screen_window_t qnxWindow, QWindow *window);
static void removeWindow(screen_window_t qnxWindow); static void removeWindow(screen_window_t qnxWindow);
@ -110,6 +114,7 @@ private:
bool m_paintUsingOpenGL; bool m_paintUsingOpenGL;
QAbstractEventDispatcher *m_eventDispatcher; QAbstractEventDispatcher *m_eventDispatcher;
QQnxServices *m_services; QQnxServices *m_services;
QList<QQnxScreen*> m_screens;
#ifndef QT_NO_CLIPBOARD #ifndef QT_NO_CLIPBOARD
mutable QQnxClipboard* m_clipboard; mutable QQnxClipboard* m_clipboard;
#endif #endif

View File

@ -42,17 +42,15 @@
#include "qqnxscreen.h" #include "qqnxscreen.h"
#include "qqnxwindow.h" #include "qqnxwindow.h"
#include <QtCore/QDebug> #ifdef QQNXSCREEN_DEBUG
#include <QtCore/QUuid> # include <QtCore/QDebug>
#endif
#include <QtGui/QWindowSystemInterface> #include <QtGui/QWindowSystemInterface>
#include <errno.h> #include <errno.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
QList<QPlatformScreen *> QQnxScreen::ms_screens;
QList<QQnxWindow*> QQnxScreen::ms_childWindows;
QQnxScreen::QQnxScreen(screen_context_t screenContext, screen_display_t display, bool primaryScreen) QQnxScreen::QQnxScreen(screen_context_t screenContext, screen_display_t display, bool primaryScreen)
: m_screenContext(screenContext), : m_screenContext(screenContext),
m_display(display), m_display(display),
@ -115,52 +113,7 @@ QQnxScreen::~QQnxScreen()
#endif #endif
} }
/* static */ static int defaultDepth()
void QQnxScreen::createDisplays(screen_context_t context)
{
#if defined(QQNXSCREEN_DEBUG)
qDebug() << Q_FUNC_INFO;
#endif
// Query number of displays
errno = 0;
int displayCount;
int result = screen_get_context_property_iv(context, SCREEN_PROPERTY_DISPLAY_COUNT, &displayCount);
if (result != 0) {
qFatal("QQnxScreen: failed to query display count, errno=%d", errno);
}
// Get all displays
errno = 0;
screen_display_t *displays = (screen_display_t *)alloca(sizeof(screen_display_t) * displayCount);
result = screen_get_context_property_pv(context, SCREEN_PROPERTY_DISPLAYS, (void **)displays);
if (result != 0) {
qFatal("QQnxScreen: failed to query displays, errno=%d", errno);
}
for (int i=0; i<displayCount; i++) {
#if defined(QQNXSCREEN_DEBUG)
qDebug() << "QQnxScreen::Creating screen for display " << i;
#endif
QQnxScreen *screen = new QQnxScreen(context, displays[i], i==0);
ms_screens.append(screen);
}
}
/* static */
void QQnxScreen::destroyDisplays()
{
#if defined(QQNXSCREEN_DEBUG)
qDebug() << Q_FUNC_INFO;
#endif
qDeleteAll(ms_screens);
ms_screens.clear();
// We're not managing the child windows anymore so we need to clear the list.
ms_childWindows.clear();
}
/* static */
int QQnxScreen::defaultDepth()
{ {
#if defined(QQNXSCREEN_DEBUG) #if defined(QQNXSCREEN_DEBUG)
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
@ -187,6 +140,11 @@ QRect QQnxScreen::availableGeometry() const
m_currentGeometry.width(), m_currentGeometry.height() - m_keyboardHeight); m_currentGeometry.width(), m_currentGeometry.height() - m_keyboardHeight);
} }
int QQnxScreen::depth() const
{
return defaultDepth();
}
/*! /*!
Check if the supplied angles are perpendicular to each other. Check if the supplied angles are perpendicular to each other.
*/ */
@ -234,17 +192,28 @@ void QQnxScreen::setRotation(int rotation)
} }
} }
QQnxWindow *QQnxScreen::findWindow(screen_window_t windowHandle)
{
Q_FOREACH (QQnxWindow *window, m_childWindows) {
QQnxWindow * const result = window->findWindow(windowHandle);
if (result)
return result;
}
return 0;
}
void QQnxScreen::addWindow(QQnxWindow *window) void QQnxScreen::addWindow(QQnxWindow *window)
{ {
#if defined(QQNXSCREEN_DEBUG) #if defined(QQNXSCREEN_DEBUG)
qDebug() << Q_FUNC_INFO << "window =" << window; qDebug() << Q_FUNC_INFO << "window =" << window;
#endif #endif
if (ms_childWindows.contains(window)) if (m_childWindows.contains(window))
return; return;
ms_childWindows.push_back(window); m_childWindows.push_back(window);
QQnxScreen::updateHierarchy(); updateHierarchy();
} }
void QQnxScreen::removeWindow(QQnxWindow *window) void QQnxScreen::removeWindow(QQnxWindow *window)
@ -253,8 +222,8 @@ void QQnxScreen::removeWindow(QQnxWindow *window)
qDebug() << Q_FUNC_INFO << "window =" << window; qDebug() << Q_FUNC_INFO << "window =" << window;
#endif #endif
ms_childWindows.removeAll(window); m_childWindows.removeAll(window);
QQnxScreen::updateHierarchy(); updateHierarchy();
} }
void QQnxScreen::raiseWindow(QQnxWindow *window) void QQnxScreen::raiseWindow(QQnxWindow *window)
@ -264,8 +233,8 @@ void QQnxScreen::raiseWindow(QQnxWindow *window)
#endif #endif
removeWindow(window); removeWindow(window);
ms_childWindows.push_back(window); m_childWindows.push_back(window);
QQnxScreen::updateHierarchy(); updateHierarchy();
} }
void QQnxScreen::lowerWindow(QQnxWindow *window) void QQnxScreen::lowerWindow(QQnxWindow *window)
@ -275,8 +244,8 @@ void QQnxScreen::lowerWindow(QQnxWindow *window)
#endif #endif
removeWindow(window); removeWindow(window);
ms_childWindows.push_front(window); m_childWindows.push_front(window);
QQnxScreen::updateHierarchy(); updateHierarchy();
} }
void QQnxScreen::updateHierarchy() void QQnxScreen::updateHierarchy()
@ -285,15 +254,15 @@ void QQnxScreen::updateHierarchy()
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
#endif #endif
QList<QQnxWindow*>::iterator it; QList<QQnxWindow*>::const_iterator it;
int topZorder = 1; // root window is z-order 0, all "top" level windows are "above" it int topZorder = 1; // root window is z-order 0, all "top" level windows are "above" it
for (it = ms_childWindows.begin(); it != ms_childWindows.end(); it++) for (it = m_childWindows.constBegin(); it != m_childWindows.constEnd(); ++it)
(*it)->updateZorder(topZorder); (*it)->updateZorder(topZorder);
// After a hierarchy update, we need to force a flush on all screens. // After a hierarchy update, we need to force a flush on all screens.
// Right now, all screens share a context. // Right now, all screens share a context.
screen_flush_context( primaryDisplay()->m_screenContext, 0 ); screen_flush_context( m_screenContext, 0 );
} }
void QQnxScreen::onWindowPost(QQnxWindow *window) void QQnxScreen::onWindowPost(QQnxWindow *window)

View File

@ -46,7 +46,6 @@
#include "qqnxrootwindow.h" #include "qqnxrootwindow.h"
#include <QtCore/QByteArray>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QScopedPointer> #include <QtCore/QScopedPointer>
@ -60,15 +59,12 @@ class QQnxScreen : public QObject, public QPlatformScreen
{ {
Q_OBJECT Q_OBJECT
public: public:
static QList<QPlatformScreen *> screens() { return ms_screens; } QQnxScreen(screen_context_t context, screen_display_t display, bool primaryScreen);
static void createDisplays(screen_context_t context); ~QQnxScreen();
static void destroyDisplays();
static QQnxScreen *primaryDisplay() { return static_cast<QQnxScreen*>(ms_screens.at(0)); }
static int defaultDepth();
QRect geometry() const { return m_currentGeometry; } QRect geometry() const { return m_currentGeometry; }
QRect availableGeometry() const; QRect availableGeometry() const;
int depth() const { return defaultDepth(); } int depth() const;
QImage::Format format() const { return (depth() == 32) ? QImage::Format_RGB32 : QImage::Format_RGB16; } QImage::Format format() const { return (depth() == 32) ? QImage::Format_RGB32 : QImage::Format_RGB16; }
QSizeF physicalSize() const { return m_currentPhysicalSize; } QSizeF physicalSize() const { return m_currentPhysicalSize; }
@ -82,12 +78,14 @@ public:
screen_context_t nativeContext() const { return m_screenContext; } screen_context_t nativeContext() const { return m_screenContext; }
const char *windowGroupName() const { return m_rootWindow->groupName().constData(); } const char *windowGroupName() const { return m_rootWindow->groupName().constData(); }
QQnxWindow *findWindow(screen_window_t windowHandle);
/* Window hierarchy management */ /* Window hierarchy management */
static void addWindow(QQnxWindow *child); void addWindow(QQnxWindow *child);
static void removeWindow(QQnxWindow *child); void removeWindow(QQnxWindow *child);
static void raiseWindow(QQnxWindow *window); void raiseWindow(QQnxWindow *window);
static void lowerWindow(QQnxWindow *window); void lowerWindow(QQnxWindow *window);
static void updateHierarchy(); void updateHierarchy();
void onWindowPost(QQnxWindow *window); void onWindowPost(QQnxWindow *window);
@ -97,11 +95,6 @@ private Q_SLOTS:
void keyboardHeightChanged(int height); void keyboardHeightChanged(int height);
private: private:
QQnxScreen(screen_context_t context, screen_display_t display, bool primaryScreen);
~QQnxScreen();
static bool orthogonal(int rotation1, int rotation2);
screen_context_t m_screenContext; screen_context_t m_screenContext;
screen_display_t m_display; screen_display_t m_display;
QSharedPointer<QQnxRootWindow> m_rootWindow; QSharedPointer<QQnxRootWindow> m_rootWindow;
@ -117,8 +110,7 @@ private:
QRect m_currentGeometry; QRect m_currentGeometry;
QPlatformOpenGLContext *m_platformContext; QPlatformOpenGLContext *m_platformContext;
static QList<QPlatformScreen *> ms_screens; QList<QQnxWindow *> m_childWindows;
static QList<QQnxWindow *> ms_childWindows;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -124,7 +124,7 @@ QQnxWindow::QQnxWindow(QWindow *window, screen_context_t context)
setScreen(static_cast<QQnxScreen *>(window->screen()->handle())); setScreen(static_cast<QQnxScreen *>(window->screen()->handle()));
// Add the window to the root of the hierarchy // Add the window to the root of the hierarchy
QQnxScreen::addWindow(this); m_screen->addWindow(this);
// Add window to plugin's window mapper // Add window to plugin's window mapper
QQnxIntegration::addWindow(m_window, window); QQnxIntegration::addWindow(m_window, window);
@ -140,7 +140,7 @@ QQnxWindow::~QQnxWindow()
// Remove from parent's Hierarchy. // Remove from parent's Hierarchy.
removeFromParent(); removeFromParent();
QQnxScreen::updateHierarchy(); m_screen->updateHierarchy();
// We shouldn't allow this case unless QT allows it. Does it? Or should we send the // We shouldn't allow this case unless QT allows it. Does it? Or should we send the
// handleCloseEvent on all children when this window is deleted? // handleCloseEvent on all children when this window is deleted?
@ -415,6 +415,11 @@ void QQnxWindow::setScreen(QQnxScreen *platformScreen)
if (m_screen == platformScreen) if (m_screen == platformScreen)
return; return;
if (m_screen && m_screen->findWindow(m_window)) {
m_screen->removeWindow(this);
platformScreen->addWindow(this);
}
m_screen = platformScreen; m_screen = platformScreen;
// Move window to proper screen/display // Move window to proper screen/display
@ -440,7 +445,7 @@ void QQnxWindow::setScreen(QQnxScreen *platformScreen)
(*it)->setScreen(platformScreen); (*it)->setScreen(platformScreen);
} }
QQnxScreen::updateHierarchy(); m_screen->updateHierarchy();
} }
void QQnxWindow::removeFromParent() void QQnxWindow::removeFromParent()
@ -455,7 +460,7 @@ void QQnxWindow::removeFromParent()
else else
qFatal("QQnxWindow: Window Hierarchy broken; window has parent, but parent hasn't got child."); qFatal("QQnxWindow: Window Hierarchy broken; window has parent, but parent hasn't got child.");
} else { } else {
QQnxScreen::removeWindow(this); m_screen->removeWindow(this);
} }
} }
@ -483,10 +488,10 @@ void QQnxWindow::setParent(const QPlatformWindow *window)
m_parentWindow->m_childWindows.push_back(this); m_parentWindow->m_childWindows.push_back(this);
} else { } else {
QQnxScreen::addWindow(this); m_screen->addWindow(this);
} }
QQnxScreen::updateHierarchy(); m_screen->updateHierarchy();
} }
void QQnxWindow::raise() void QQnxWindow::raise()
@ -500,10 +505,10 @@ void QQnxWindow::raise()
removeFromParent(); removeFromParent();
oldParent->m_childWindows.push_back(this); oldParent->m_childWindows.push_back(this);
} else { } else {
QQnxScreen::raiseWindow(this); m_screen->raiseWindow(this);
} }
QQnxScreen::updateHierarchy(); m_screen->updateHierarchy();
} }
void QQnxWindow::lower() void QQnxWindow::lower()
@ -517,10 +522,10 @@ void QQnxWindow::lower()
removeFromParent(); removeFromParent();
oldParent->m_childWindows.push_front(this); oldParent->m_childWindows.push_front(this);
} else { } else {
QQnxScreen::lowerWindow(this); m_screen->lowerWindow(this);
} }
QQnxScreen::updateHierarchy(); m_screen->updateHierarchy();
} }
void QQnxWindow::requestActivateWindow() void QQnxWindow::requestActivateWindow()
@ -552,6 +557,20 @@ void QQnxWindow::setPlatformOpenGLContext(QQnxGLContext *platformOpenGLContext)
m_platformOpenGLContext = platformOpenGLContext; m_platformOpenGLContext = platformOpenGLContext;
} }
QQnxWindow *QQnxWindow::findWindow(screen_window_t windowHandle)
{
if (m_window == windowHandle)
return this;
Q_FOREACH (QQnxWindow *window, m_childWindows) {
QQnxWindow * const result = window->findWindow(windowHandle);
if (result)
return result;
}
return 0;
}
void QQnxWindow::updateZorder(int &topZorder) void QQnxWindow::updateZorder(int &topZorder)
{ {
errno = 0; errno = 0;

View File

@ -99,6 +99,8 @@ public:
void setPlatformOpenGLContext(QQnxGLContext *platformOpenGLContext); void setPlatformOpenGLContext(QQnxGLContext *platformOpenGLContext);
QQnxGLContext *platformOpenGLContext() const { return m_platformOpenGLContext; } QQnxGLContext *platformOpenGLContext() const { return m_platformOpenGLContext; }
QQnxWindow *findWindow(screen_window_t windowHandle);
private: private:
void removeFromParent(); void removeFromParent();
void offset(const QPoint &offset); void offset(const QPoint &offset);