[QNX] Introduce proper screen error handling

This patch adds a new function which does the error handling for libscreen calls.
The patch introduces following changes:
- Libscreen errors will not crash (qFatal)the application any more but rather post a
warning message.
-With the "flush-screen-context" option the screen_context is always
flushed when a screen function is called. This enables better correlation between the
time an error happens and the time it is logged.

Change-Id: Ie2456e5b746dcf917d786f3b832847d2ebbe5f1e
Reviewed-by: Kevin Krammer <kevin.krammer@kdab.com>
Reviewed-by: Roger Maclean <rmaclean@qnx.com>
Reviewed-by: Bernd Weimer <bweimer@blackberry.com>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
This commit is contained in:
Fabian Bumberger 2014-01-17 20:45:57 +01:00 committed by The Qt Project
parent a4ff400e25
commit b8103a4e81
11 changed files with 332 additions and 261 deletions

View File

@ -45,7 +45,8 @@ SOURCES = main.cpp \
qqnxabstractvirtualkeyboard.cpp \
qqnxservices.cpp \
qqnxcursor.cpp \
qqnxrasterwindow.cpp
qqnxrasterwindow.cpp \
qqnxglobal.cpp
HEADERS = main.h \
qqnxbuffer.h \
@ -63,7 +64,8 @@ HEADERS = main.h \
qqnxservices.h \
qqnxcursor.h \
qqnxrasterwindow.h \
qqnxscreeneventfilter.h
qqnxscreeneventfilter.h \
qqnxglobal.h
CONFIG(qqnx_screeneventthread) {
DEFINES += QQNX_SCREENEVENTTHREAD

View File

@ -39,6 +39,8 @@
**
****************************************************************************/
#include "qqnxglobal.h"
#include "qqnxbuffer.h"
#include <QtCore/QDebug>
@ -66,34 +68,30 @@ QQnxBuffer::QQnxBuffer(screen_buffer_t buffer)
qBufferDebug() << Q_FUNC_INFO << "normal";
// Get size of buffer
errno = 0;
int size[2];
int result = screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_BUFFER_SIZE, size);
if (result != 0)
qFatal("QQNX: failed to query buffer size, errno=%d", errno);
Q_SCREEN_CRITICALERROR(screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_BUFFER_SIZE, size),
"Failed to query buffer size");
// Get stride of buffer
errno = 0;
int stride;
result = screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_STRIDE, &stride);
if (result != 0)
qFatal("QQNX: failed to query buffer stride, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_STRIDE, &stride),
"Failed to query buffer stride");
// Get access to buffer's data
errno = 0;
uchar *dataPtr = 0;
result = screen_get_buffer_property_pv(buffer, SCREEN_PROPERTY_POINTER, (void **)&dataPtr);
if (result != 0)
qFatal("QQNX: failed to query buffer pointer, errno=%d", errno);
Q_SCREEN_CRITICALERROR(
screen_get_buffer_property_pv(buffer, SCREEN_PROPERTY_POINTER, (void **)&dataPtr),
"Failed to query buffer pointer");
if (dataPtr == 0)
qFatal("QQNX: buffer pointer is NULL, errno=%d", errno);
// Get format of buffer
errno = 0;
int screenFormat;
result = screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_FORMAT, &screenFormat);
if (result != 0)
qFatal("QQNX: failed to query buffer format, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_FORMAT, &screenFormat),
"Failed to query buffer format");
// Convert screen format to QImage format
QImage::Format imageFormat = QImage::Format_Invalid;

View File

@ -0,0 +1,63 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2014 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <errno.h>
#include <QDebug>
#include "qqnxintegration.h"
QT_BEGIN_NAMESPACE
void qScreenCheckError(int rc, const char *funcInfo, const char *message, bool critical)
{
if (!rc && (QQnxIntegration::options() & QQnxIntegration::AlwaysFlushScreenContext)
&& QQnxIntegration::screenContext() != 0) {
rc = screen_flush_context(QQnxIntegration::screenContext(), 0);
}
if (rc) {
if (critical)
qCritical("%s - Screen: %s - Error: %s (%i)", funcInfo, message, strerror(errno), errno);
else
qWarning("%s - Screen: %s - Error: %s (%i)", funcInfo, message, strerror(errno), errno);
}
}
QT_END_NAMESPACE

View File

@ -0,0 +1,59 @@
/***************************************************************************
**
** Copyright (C) 2011 - 2014 BlackBerry Limited. All rights reserved.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QQNXGLOBAL_H
#define QQNXGLOBAL_H
#include <qglobal.h>
QT_BEGIN_NAMESPACE
void qScreenCheckError(int rc, const char *funcInfo, const char *message, bool critical);
#define Q_SCREEN_CHECKERROR(x, message) \
qScreenCheckError(x, Q_FUNC_INFO, message, false)
#define Q_SCREEN_CRITICALERROR(x, message) \
qScreenCheckError(x, Q_FUNC_INFO, message, true)
QT_END_NAMESPACE
#endif // QQNXGLOBAL_H

View File

@ -39,6 +39,8 @@
**
****************************************************************************/
#include "qqnxglobal.h"
#include "qqnxintegration.h"
#if defined(QQNX_SCREENEVENTTHREAD)
#include "qqnxscreeneventthread.h"
@ -123,6 +125,10 @@ static inline QQnxIntegration::Options parseOptions(const QStringList &paramList
options |= QQnxIntegration::FullScreenApplication;
}
if (!paramList.contains(QLatin1String("flush-screen-context"))) {
options |= QQnxIntegration::AlwaysFlushScreenContext;
}
// On Blackberry the first window is treated as a root window
#ifdef Q_OS_BLACKBERRY
if (!paramList.contains(QLatin1String("no-rootwindow"))) {
@ -165,14 +171,12 @@ QQnxIntegration::QQnxIntegration(const QStringList &paramList)
#if !defined(QT_NO_DRAGANDDROP)
, m_drag(new QSimpleDrag())
#endif
, m_options(parseOptions(paramList))
{
ms_options = parseOptions(paramList);
qIntegrationDebug() << Q_FUNC_INFO;
// Open connection to QNX composition manager
errno = 0;
int result = screen_create_context(&m_screenContext, SCREEN_APPLICATION_CONTEXT);
if (result != 0)
qFatal("QQnx: failed to connect to composition manager, errno=%d", errno);
Q_SCREEN_CRITICALERROR(screen_create_context(&ms_screenContext, SCREEN_APPLICATION_CONTEXT),
"Failed to create screen context");
// Not on BlackBerry, it has specialized event dispatcher which also handles navigator events
#if !defined(Q_OS_BLACKBERRY) && defined(QQNX_PPS)
@ -191,7 +195,7 @@ QQnxIntegration::QQnxIntegration(const QStringList &paramList)
// Create/start event thread
#if defined(QQNX_SCREENEVENTTHREAD)
m_screenEventThread = new QQnxScreenEventThread(m_screenContext, m_screenEventHandler);
m_screenEventThread = new QQnxScreenEventThread(ms_screenContext, m_screenEventHandler);
m_screenEventThread->start();
#endif
@ -306,7 +310,7 @@ QQnxIntegration::~QQnxIntegration()
destroyDisplays();
// Close connection to QNX composition manager
screen_destroy_context(m_screenContext);
screen_destroy_context(ms_screenContext);
#if !defined(QT_NO_OPENGL)
// Cleanup global OpenGL resources
@ -358,10 +362,10 @@ QPlatformWindow *QQnxIntegration::createPlatformWindow(QWindow *window) const
const bool needRootWindow = options() & RootWindow;
switch (surfaceType) {
case QSurface::RasterSurface:
return new QQnxRasterWindow(window, m_screenContext, needRootWindow);
return new QQnxRasterWindow(window, ms_screenContext, needRootWindow);
#if !defined(QT_NO_OPENGL)
case QSurface::OpenGLSurface:
return new QQnxEglWindow(window, m_screenContext, needRootWindow);
return new QQnxEglWindow(window, ms_screenContext, needRootWindow);
#endif
default:
qFatal("QQnxWindow: unsupported window API");
@ -444,7 +448,7 @@ QPlatformDrag *QQnxIntegration::drag() const
QVariant QQnxIntegration::styleHint(QPlatformIntegration::StyleHint hint) const
{
qIntegrationDebug() << Q_FUNC_INFO;
if ((hint == ShowIsFullScreen) && (m_options & FullScreenApplication))
if ((hint == ShowIsFullScreen) && (ms_options & FullScreenApplication))
return true;
return QPlatformIntegration::styleHint(hint);
@ -498,11 +502,10 @@ void QQnxIntegration::createDisplays()
{
qIntegrationDebug() << Q_FUNC_INFO;
// 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);
int displayCount = 0;
int result = screen_get_context_property_iv(ms_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT,
&displayCount);
Q_SCREEN_CRITICALERROR(result, "Failed to query display count");
if (displayCount < 1) {
// Never happens, even if there's no display, libscreen returns 1
@ -510,23 +513,20 @@ void QQnxIntegration::createDisplays()
}
// 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);
result = screen_get_context_property_pv(ms_screenContext, SCREEN_PROPERTY_DISPLAYS,
(void **)displays);
Q_SCREEN_CRITICALERROR(result, "Failed to query displays");
// If it's primary, we create a QScreen for it even if it's not attached
// since Qt will dereference QGuiApplication::primaryScreen()
createDisplay(displays[0], /*isPrimary=*/true);
for (int i=1; i<displayCount; i++) {
int isAttached = 0;
result = screen_get_display_property_iv(displays[i], SCREEN_PROPERTY_ATTACHED, &isAttached);
if (result != 0) {
qWarning("QQnxIntegration: failed to query display attachment, errno=%d", errno);
isAttached = 1; // assume attached
}
int isAttached = 1;
result = screen_get_display_property_iv(displays[i], SCREEN_PROPERTY_ATTACHED,
&isAttached);
Q_SCREEN_CHECKERROR(result, "Failed to query display attachment");
if (!isAttached) {
qIntegrationDebug() << Q_FUNC_INFO << "Skipping non-attached display" << i;
@ -540,7 +540,7 @@ void QQnxIntegration::createDisplays()
void QQnxIntegration::createDisplay(screen_display_t display, bool isPrimary)
{
QQnxScreen *screen = new QQnxScreen(m_screenContext, display, isPrimary);
QQnxScreen *screen = new QQnxScreen(ms_screenContext, display, isPrimary);
m_screens.append(screen);
screenAdded(screen);
screen->adjustOrientation();
@ -587,11 +587,20 @@ QQnxScreen *QQnxIntegration::primaryDisplay() const
return m_screens.first();
}
QQnxIntegration::Options QQnxIntegration::options() const
QQnxIntegration::Options QQnxIntegration::options()
{
return m_options;
return ms_options;
}
screen_context_t QQnxIntegration::screenContext()
{
return ms_screenContext;
}
screen_context_t QQnxIntegration::ms_screenContext = 0;
QQnxIntegration::Options QQnxIntegration::ms_options = 0;
bool QQnxIntegration::supportsNavigatorEvents() const
{
// If QQNX_PPS or Q_OS_BLACKBERRY is defined then we have navigator

View File

@ -85,7 +85,8 @@ public:
enum Option { // Options to be passed on command line.
NoOptions = 0x0,
FullScreenApplication = 0x1,
RootWindow = 0x2
RootWindow = 0x2,
AlwaysFlushScreenContext = 0x4
};
Q_DECLARE_FLAGS(Options, Option)
explicit QQnxIntegration(const QStringList &paramList);
@ -137,7 +138,8 @@ public:
void createDisplay(screen_display_t display, bool isPrimary);
void removeDisplay(QQnxScreen *screen);
QQnxScreen *primaryDisplay() const;
Options options() const;
static Options options();
static screen_context_t screenContext();
private:
void createDisplays();
@ -146,7 +148,7 @@ private:
static void addWindow(screen_window_t qnxWindow, QWindow *window);
static void removeWindow(screen_window_t qnxWindow);
screen_context_t m_screenContext;
static screen_context_t ms_screenContext;
#if defined(QQNX_SCREENEVENTTHREAD)
QQnxScreenEventThread *m_screenEventThread;
#endif
@ -176,7 +178,7 @@ private:
static QQnxWindowMapper ms_windowMapper;
static QMutex ms_windowMapperMutex;
const Options m_options;
static Options ms_options;
friend class QQnxWindow;
};

View File

@ -39,6 +39,8 @@
**
****************************************************************************/
#include "qqnxglobal.h"
#include "qqnxrasterwindow.h"
#include "qqnxscreen.h"
@ -102,10 +104,9 @@ void QQnxRasterWindow::post(const QRegion &dirty)
int dirtyRect[4] = { rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height() };
// Update the display with contents of render buffer
errno = 0;
int result = screen_post_window(nativeHandle(), currentBuffer.nativeBuffer(), 1, dirtyRect, 0);
if (result != 0)
qFatal("QQnxWindow: failed to post window buffer, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_post_window(nativeHandle(), currentBuffer.nativeBuffer(), 1, dirtyRect, 0),
"Failed to post window");
// Advance to next nender buffer
m_previousBufferIndex = m_currentBufferIndex++;
@ -135,28 +136,23 @@ QQnxBuffer &QQnxRasterWindow::renderBuffer()
// Check if render buffer is invalid
if (m_currentBufferIndex == -1) {
// Get all buffers available for rendering
errno = 0;
screen_buffer_t buffers[MAX_BUFFER_COUNT];
int result = screen_get_window_property_pv(nativeHandle(), SCREEN_PROPERTY_RENDER_BUFFERS, (void **)buffers);
if (result != 0)
qFatal("QQnxRasterWindow: failed to query window buffers, errno=%d", errno);
const int result = screen_get_window_property_pv(nativeHandle(), SCREEN_PROPERTY_RENDER_BUFFERS,
(void **)buffers);
Q_SCREEN_CRITICALERROR(result, "Failed to query window buffers");
// Wrap each buffer and clear
for (int i = 0; i < MAX_BUFFER_COUNT; ++i) {
m_buffers[i] = QQnxBuffer(buffers[i]);
// Clear Buffer
errno = 0;
int bg[] = { SCREEN_BLIT_COLOR, 0x00000000, SCREEN_BLIT_END };
result = screen_fill(screen()->nativeContext(), buffers[i], bg);
if (result != 0)
qFatal("QQnxWindow: failed to clear window buffer, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_fill(screen()->nativeContext(), buffers[i], bg),
"Failed to clear window buffer");
}
errno = 0;
result = screen_flush_blits(screen()->nativeContext(), 0);
if (result != 0)
qFatal("QQnxWindow: failed to flush blits, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_flush_blits(screen()->nativeContext(), 0),
"Failed to flush blits");
// Use the first available render buffer
m_currentBufferIndex = 0;
@ -220,20 +216,16 @@ void QQnxRasterWindow::blitPreviousToCurrent(const QRegion &region, int dx, int
SCREEN_BLIT_END };
// Queue blit operation
errno = 0;
const int result = screen_blit(m_screenContext, currentBuffer.nativeBuffer(),
previousBuffer.nativeBuffer(), attribs);
if (result != 0)
qFatal("QQnxWindow: failed to blit buffers, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_blit(m_screenContext, currentBuffer.nativeBuffer(),
previousBuffer.nativeBuffer(), attribs),
"Failed to blit buffers");
}
// Check if flush requested
if (flush) {
// Wait for all blits to complete
errno = 0;
const int result = screen_flush_blits(m_screenContext, SCREEN_WAIT_IDLE);
if (result != 0)
qFatal("QQnxWindow: failed to flush blits, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_flush_blits(m_screenContext, SCREEN_WAIT_IDLE),
"Failed to flush blits");
// Buffer was modified outside the CPU
currentBuffer.invalidateInCache();

View File

@ -39,6 +39,8 @@
**
****************************************************************************/
#include "qqnxglobal.h"
#include "qqnxscreen.h"
#include "qqnxwindow.h"
#include "qqnxcursor.h"
@ -75,10 +77,9 @@ QT_BEGIN_NAMESPACE
static QSize determineScreenSize(screen_display_t display, bool primaryScreen) {
int val[2];
errno = 0;
const int result = screen_get_display_property_iv(display, SCREEN_PROPERTY_PHYSICAL_SIZE, val);
Q_SCREEN_CHECKERROR(result, "Failed to query display physical size");
if (result != 0) {
qFatal("QQnxScreen: failed to query display physical size, errno=%d", errno);
return QSize(150, 90);
}
@ -163,19 +164,16 @@ QQnxScreen::QQnxScreen(screen_context_t screenContext, screen_display_t display,
{
qScreenDebug() << Q_FUNC_INFO;
// Cache initial orientation of this display
errno = 0;
int result = screen_get_display_property_iv(m_display, SCREEN_PROPERTY_ROTATION, &m_initialRotation);
if (result != 0)
qFatal("QQnxScreen: failed to query display rotation, errno=%d", errno);
int result = screen_get_display_property_iv(m_display, SCREEN_PROPERTY_ROTATION,
&m_initialRotation);
Q_SCREEN_CHECKERROR(result, "Failed to query display rotation");
m_currentRotation = m_initialRotation;
// Cache size of this display in pixels
errno = 0;
int val[2];
result = screen_get_display_property_iv(m_display, SCREEN_PROPERTY_SIZE, val);
if (result != 0)
qFatal("QQnxScreen: failed to query display size, errno=%d", errno);
Q_SCREEN_CRITICALERROR(screen_get_display_property_iv(m_display, SCREEN_PROPERTY_SIZE, val),
"Failed to query display size");
m_currentGeometry = m_initialGeometry = QRect(0, 0, val[0], val[1]);

View File

@ -39,6 +39,8 @@
**
****************************************************************************/
#include "qqnxglobal.h"
#include "qqnxscreeneventhandler.h"
#if defined(QQNX_SCREENEVENTTHREAD)
#include "qqnxscreeneventthread.h"
@ -104,11 +106,9 @@ void QQnxScreenEventHandler::removeScreenEventFilter(QQnxScreenEventFilter *filt
bool QQnxScreenEventHandler::handleEvent(screen_event_t event)
{
// get the event type
errno = 0;
int qnxType;
int result = screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &qnxType);
if (result)
qFatal("QQNX: failed to query event type, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &qnxType),
"Failed to query event type");
return handleEvent(event, qnxType);
}
@ -239,39 +239,32 @@ void QQnxScreenEventHandler::processEventsFromScreenThread()
void QQnxScreenEventHandler::handleKeyboardEvent(screen_event_t event)
{
// get flags of key event
errno = 0;
int flags;
int result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_FLAGS, &flags);
if (result)
qFatal("QQNX: failed to query event flags, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_FLAGS, &flags),
"Failed to query event flags");
// get key code
errno = 0;
int sym;
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SYM, &sym);
if (result)
qFatal("QQNX: failed to query event sym, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SYM, &sym),
"Failed to query event sym");
int modifiers;
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_MODIFIERS, &modifiers);
if (result)
qFatal("QQNX: failed to query event modifiers, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_MODIFIERS, &modifiers),
"Failed to query event modifieres");
int scan;
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SCAN, &scan);
if (result)
qFatal("QQNX: failed to query event modifiers, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SCAN, &scan),
"Failed to query event scan");
int cap;
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_CAP, &cap);
if (result)
qFatal("QQNX: failed to query event cap, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_CAP, &cap),
"Failed to query event cap");
int sequenceId = 0;
#if defined(Q_OS_BLACKBERRY)
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_SEQUENCE_ID, &sequenceId);
if (result)
qFatal("QQNX: failed to query event seqId, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_get_event_property_iv(event, SCREEN_PROPERTY_SEQUENCE_ID, &sequenceId),
"Failed to query event seqId");
#endif
bool inject = true;
@ -293,35 +286,32 @@ void QQnxScreenEventHandler::handlePointerEvent(screen_event_t event)
// Query the window that was clicked
screen_window_t qnxWindow;
void *handle;
int result = screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, &handle);
if (result)
qFatal("QQNX: failed to query event window, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, &handle),
"Failed to query event window");
qnxWindow = static_cast<screen_window_t>(handle);
// Query the button states
int buttonState = 0;
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_BUTTONS, &buttonState);
if (result)
qFatal("QQNX: failed to query event button state, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_BUTTONS, &buttonState),
"Failed to query event button state");
// Query the window position
int windowPos[2];
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, windowPos);
if (result)
qFatal("QQNX: failed to query event window position, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, windowPos),
"Failed to query event window position");
// Query the screen position
int pos[2];
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_POSITION, pos);
if (result)
qFatal("QQNX: failed to query event position, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_POSITION, pos),
"Failed to query event position");
// Query the wheel delta
int wheelDelta = 0;
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_MOUSE_WHEEL, &wheelDelta);
if (result)
qFatal("QQNX: failed to query event wheel delta, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_get_event_property_iv(event, SCREEN_PROPERTY_MOUSE_WHEEL, &wheelDelta),
"Failed to query event wheel delta");
// Map window handle to top-level QWindow
QWindow *w = QQnxIntegration::window(qnxWindow);
@ -399,47 +389,36 @@ void QQnxScreenEventHandler::handlePointerEvent(screen_event_t event)
void QQnxScreenEventHandler::handleTouchEvent(screen_event_t event, int qnxType)
{
// get display coordinates of touch
errno = 0;
int pos[2];
int result = screen_get_event_property_iv(event, SCREEN_PROPERTY_POSITION, pos);
if (result)
qFatal("QQNX: failed to query event position, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_POSITION, pos),
"Failed to query event position");
QCursor::setPos(pos[0], pos[1]);
// get window coordinates of touch
errno = 0;
int windowPos[2];
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, windowPos);
if (result)
qFatal("QQNX: failed to query event window position, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, windowPos),
"Failed to query event window position");
// determine which finger touched
errno = 0;
int touchId;
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_ID, &touchId);
if (result)
qFatal("QQNX: failed to query event touch id, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_ID, &touchId),
"Failed to query event touch id");
// determine which window was touched
errno = 0;
void *handle;
result = screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, &handle);
if (result)
qFatal("QQNX: failed to query event window, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, &handle),
"Failed to query event window");
errno = 0;
int touchArea[2];
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_SIZE, touchArea);
if (result)
qFatal("QQNX: failed to query event touch area, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_SIZE, touchArea),
"Failed to query event touch area");
errno = 0;
int touchPressure;
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_PRESSURE, &touchPressure);
if (result)
qFatal("QQNX: failed to query event touch pressure, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_PRESSURE, &touchPressure),
"Failed to query event touch pressure");
screen_window_t qnxWindow = static_cast<screen_window_t>(handle);
@ -534,8 +513,9 @@ void QQnxScreenEventHandler::handleTouchEvent(screen_event_t event, int qnxType)
void QQnxScreenEventHandler::handleCloseEvent(screen_event_t event)
{
screen_window_t window = 0;
if (screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0)
qFatal("QQnx: failed to query window property, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, (void**)&window),
"Failed to query window property");
Q_EMIT windowClosed(window);
@ -548,8 +528,9 @@ void QQnxScreenEventHandler::handleCloseEvent(screen_event_t event)
void QQnxScreenEventHandler::handleCreateEvent(screen_event_t event)
{
screen_window_t window = 0;
if (screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0)
qFatal("QQnx: failed to query window property, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_get_event_property_pv(event, SCREEN_PROPERTY_WINDOW, (void**)&window),
"Failed to query window property");
Q_EMIT newWindowCreated(window);
}
@ -601,8 +582,9 @@ void QQnxScreenEventHandler::handlePropertyEvent(screen_event_t event)
{
errno = 0;
int objectType;
if (screen_get_event_property_iv(event, SCREEN_PROPERTY_OBJECT_TYPE, &objectType) != 0)
qFatal("QQNX: failed to query object type property, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_get_event_property_iv(event, SCREEN_PROPERTY_OBJECT_TYPE, &objectType),
"Failed to query object type property");
if (objectType != SCREEN_OBJECT_TYPE_WINDOW)
return;

View File

@ -39,6 +39,8 @@
**
****************************************************************************/
#include "qqnxglobal.h"
#include "qqnxscreeneventthread.h"
#include "qqnxscreeneventhandler.h"
@ -92,30 +94,34 @@ void QQnxScreenEventThread::run()
{
qScreenEventThreadDebug() << Q_FUNC_INFO << "screen event thread started";
int errorCounter = 0;
// loop indefinitely
while (!m_quit) {
screen_event_t event;
// create screen event
errno = 0;
int result = screen_create_event(&event);
if (result)
qFatal("QQNX: failed to create screen event, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_create_event(&event), "Failed to create screen event");
// block until screen event is available
errno = 0;
result = screen_get_event(m_screenContext, event, -1);
if (result)
qFatal("QQNX: failed to get screen event, errno=%d", errno);
const int result = screen_get_event(m_screenContext, event, -1);
Q_SCREEN_CRITICALERROR(result, "Failed to get screen event");
// Only allow 50 consecutive errors before we exit the thread
if (!result) {
errorCounter++;
if (errorCounter > 50)
m_quit = true;
screen_destroy_event(event);
continue;
} else {
errorCounter = 0;
}
// process received event
// get the event type
errno = 0;
int qnxType;
result = screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &qnxType);
if (result)
qFatal("QQNX: failed to query screen event type, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &qnxType),
"Failed to query screen event type");
if (qnxType == SCREEN_EVENT_USER) {
// treat all user events as shutdown requests
@ -145,25 +151,19 @@ void QQnxScreenEventThread::shutdown()
screen_event_t event;
// create screen event
errno = 0;
int result = screen_create_event(&event);
if (result)
qFatal("QQNX: failed to create screen event, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_create_event(&event),
"Failed to create screen event");
// set the event type as user
errno = 0;
int type = SCREEN_EVENT_USER;
result = screen_set_event_property_iv(event, SCREEN_PROPERTY_TYPE, &type);
if (result)
qFatal("QQNX: failed to set screen event type, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_set_event_property_iv(event, SCREEN_PROPERTY_TYPE, &type),
"Failed to set screen type");
// NOTE: ignore SCREEN_PROPERTY_USER_DATA; treat all user events as shutdown events
// post event to event loop so it will wake up and die
errno = 0;
result = screen_send_event(m_screenContext, event, getpid());
if (result)
qFatal("QQNX: failed to set screen event type, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_send_event(m_screenContext, event, getpid()),
"Failed to set screen event type");
// cleanup
screen_destroy_event(event);

View File

@ -39,6 +39,8 @@
**
****************************************************************************/
#include "qqnxglobal.h"
#include "qqnxwindow.h"
#include "qqnxintegration.h"
#include "qqnxscreen.h"
@ -82,7 +84,6 @@ QQnxWindow::QQnxWindow(QWindow *window, screen_context_t context, bool needRootW
m_mmRendererWindow(0)
{
qWindowDebug() << Q_FUNC_INFO << "window =" << window << ", size =" << window->size();
int result;
QQnxScreen *platformScreen = static_cast<QQnxScreen *>(window->screen()->handle());
@ -99,18 +100,18 @@ QQnxWindow::QQnxWindow(QWindow *window, screen_context_t context, bool needRootW
m_isTopLevel = !needRootWindow || !platformScreen->rootWindow();
}
errno = 0;
if (m_isTopLevel) {
result = screen_create_window(&m_window, m_screenContext); // Creates an application window
Q_SCREEN_CRITICALERROR(screen_create_window(&m_window, m_screenContext),
"Could not create top level window"); // Creates an application window
if (window->type() != Qt::CoverWindow) {
if (needRootWindow)
platformScreen->setRootWindow(this);
}
} else {
result = screen_create_window_type(&m_window, m_screenContext, SCREEN_CHILD_WINDOW);
Q_SCREEN_CHECKERROR(
screen_create_window_type(&m_window, m_screenContext, SCREEN_CHILD_WINDOW),
"Could not create child window");
}
if (result != 0)
qFatal("QQnxWindow: failed to create window, errno=%d", errno);
createWindowGroup();
}
@ -162,26 +163,20 @@ void QQnxWindow::setGeometryHelper(const QRect &rect)
QPlatformWindow::setGeometry(rect);
// Set window geometry equal to widget geometry
errno = 0;
int val[2];
val[0] = rect.x();
val[1] = rect.y();
int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, val);
if (result != 0)
qFatal("QQnxWindow: failed to set window position, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, val),
"Failed to set window position");
errno = 0;
val[0] = rect.width();
val[1] = rect.height();
result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val);
if (result != 0)
qFatal("QQnxWindow: failed to set window size, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val),
"Failed to set window size");
// Set viewport size equal to window size
errno = 0;
result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val);
if (result != 0)
qFatal("QQnxWindow: failed to set window source size, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val),
"Failed to set window source size");
screen_flush_context(m_screenContext, 0);
}
@ -223,11 +218,9 @@ void QQnxWindow::updateVisibility(bool parentVisible)
{
qWindowDebug() << Q_FUNC_INFO << "parentVisible =" << parentVisible << "window =" << window();
// Set window visibility
errno = 0;
int val = (m_visible && parentVisible) ? 1 : 0;
int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_VISIBLE, &val);
if (result != 0)
qFatal("QQnxWindow: failed to set window visibility, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_VISIBLE, &val),
"Failed to set window visibility");
Q_FOREACH (QQnxWindow *childWindow, m_childWindows)
childWindow->updateVisibility(m_visible && parentVisible);
@ -237,11 +230,9 @@ void QQnxWindow::setOpacity(qreal level)
{
qWindowDebug() << Q_FUNC_INFO << "window =" << window() << "opacity =" << level;
// Set window global alpha
errno = 0;
int val = (int)(level * 255);
int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_GLOBAL_ALPHA, &val);
if (result != 0)
qFatal("QQnxWindow: failed to set window global alpha, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_GLOBAL_ALPHA, &val),
"Failed to set global alpha");
screen_flush_context(m_screenContext, 0);
}
@ -266,15 +257,12 @@ void QQnxWindow::setBufferSize(const QSize &size)
qWindowDebug() << Q_FUNC_INFO << "window =" << window() << "size =" << size;
// Set window buffer size
errno = 0;
// libscreen fails when creating empty buffers
const QSize nonEmptySize = size.isEmpty() ? QSize(1, 1) : size;
int val[2] = { nonEmptySize.width(), nonEmptySize.height() };
int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, val);
if (result != 0)
qFatal("QQnxWindow: failed to set window buffer size, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, val),
"Failed to set window buffer size");
// Create window buffers if they do not exist
if (m_bufferSize.isEmpty()) {
@ -282,24 +270,18 @@ void QQnxWindow::setBufferSize(const QSize &size)
if (val[0] == -1) // The platform GL context was not set yet on the window, so we can't procede
return;
errno = 0;
result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, val);
if (result != 0)
qFatal("QQnxWindow: failed to set window pixel format, errno=%d", errno);
Q_SCREEN_CRITICALERROR(
screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, val),
"Failed to set window format");
errno = 0;
result = screen_create_window_buffers(m_window, MAX_BUFFER_COUNT);
if (result != 0) {
qWarning() << "QQnxWindow: Buffer size was" << size;
qFatal("QQnxWindow: failed to create window buffers, errno=%d", errno);
}
Q_SCREEN_CRITICALERROR(screen_create_window_buffers(m_window, MAX_BUFFER_COUNT),
"Failed to create window buffers");
// check if there are any buffers available
int bufferCount = 0;
result = screen_get_window_property_iv(m_window, SCREEN_PROPERTY_RENDER_BUFFER_COUNT, &bufferCount);
if (result != 0)
qFatal("QQnxWindow: failed to query window buffer count, errno=%d", errno);
Q_SCREEN_CRITICALERROR(
screen_get_window_property_iv(m_window, SCREEN_PROPERTY_RENDER_BUFFER_COUNT, &bufferCount),
"Failed to query render buffer count");
if (bufferCount != MAX_BUFFER_COUNT) {
qFatal("QQnxWindow: invalid buffer count. Expected = %d, got = %d. You might experience problems.",
@ -322,10 +304,8 @@ void QQnxWindow::setBufferSize(const QSize &size)
val[0] = SCREEN_TRANSPARENCY_SOURCE_OVER;
}
errno = 0;
result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_TRANSPARENCY, val);
if (result != 0)
qFatal("QQnxWindow: failed to set window transparency, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_TRANSPARENCY, val),
"Failed to set window transparency");
// Cache new buffer size
m_bufferSize = nonEmptySize;
@ -350,9 +330,8 @@ void QQnxWindow::setScreen(QQnxScreen *platformScreen)
if (m_screen) {
qWindowDebug() << Q_FUNC_INFO << "Moving window to different screen";
m_screen->removeWindow(this);
QQnxIntegration *platformIntegration = static_cast<QQnxIntegration*>(QGuiApplicationPrivate::platformIntegration());
if ((platformIntegration->options() & QQnxIntegration::RootWindow)) {
if ((QQnxIntegration::options() & QQnxIntegration::RootWindow)) {
screen_leave_window_group(m_window);
}
}
@ -363,14 +342,11 @@ void QQnxWindow::setScreen(QQnxScreen *platformScreen)
}
if (m_isTopLevel) {
// Move window to proper screen/display
errno = 0;
screen_display_t display = platformScreen->nativeDisplay();
int result = screen_set_window_property_pv(m_window, SCREEN_PROPERTY_DISPLAY, (void **)&display);
if (result != 0)
qFatal("QQnxWindow: failed to set window display, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_set_window_property_pv(m_window, SCREEN_PROPERTY_DISPLAY, (void **)&display),
"Failed to set window display");
} else {
errno = 0;
Q_FOREACH (QQnxWindow *childWindow, m_childWindows) {
// Only subwindows and tooltips need necessarily be moved to another display with the window.
if (window()->type() == Qt::SubWindow || window()->type() == Qt::ToolTip)
@ -532,34 +508,29 @@ void QQnxWindow::minimize()
void QQnxWindow::setRotation(int rotation)
{
qWindowDebug() << Q_FUNC_INFO << "angle =" << rotation;
errno = 0;
int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ROTATION, &rotation);
if (result != 0)
qFatal("QQnxRootWindow: failed to set window rotation, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ROTATION, &rotation),
"Failed to set window rotation");
}
void QQnxWindow::initWindow()
{
// Alpha channel is always pre-multiplied if present
errno = 0;
int val = SCREEN_PRE_MULTIPLIED_ALPHA;
int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ALPHA_MODE, &val);
if (result != 0)
qFatal("QQnxWindow: failed to set window alpha mode, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ALPHA_MODE, &val),
"Failed to set alpha mode");
// Set the window swap interval
errno = 0;
val = 1;
result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SWAP_INTERVAL, &val);
if (result != 0)
qFatal("QQnxWindow: failed to set window swap interval, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SWAP_INTERVAL, &val),
"Failed to set swap interval");
if (window()->flags() & Qt::WindowDoesNotAcceptFocus) {
errno = 0;
val = SCREEN_SENSITIVITY_NO_FOCUS;
result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SENSITIVITY, &val);
if (result != 0)
qFatal("QQnxWindow: failed to set window sensitivity, errno=%d", errno);
Q_SCREEN_CHECKERROR(
screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SENSITIVITY, &val),
"Failed to set window sensitivity");
}
QQnxScreen *platformScreen = static_cast<QQnxScreen *>(window()->screen()->handle());
@ -602,10 +573,8 @@ void QQnxWindow::createWindowGroup()
m_windowGroupName = QUuid::createUuid().toString().toLatin1();
// Create window group so child windows can be parented by container window
errno = 0;
int result = screen_create_window_group(m_window, m_windowGroupName.constData());
if (result != 0)
qFatal("QQnxRootWindow: failed to create app window group, errno=%d", errno);
Q_SCREEN_CHECKERROR(screen_create_window_group(m_window, m_windowGroupName.constData()),
"Failed to create window group");
}
void QQnxWindow::joinWindowGroup(const QByteArray &groupName)
@ -649,12 +618,9 @@ void QQnxWindow::updateZorder(int &topZorder)
void QQnxWindow::updateZorder(screen_window_t window, int &topZorder)
{
errno = 0;
int result = screen_set_window_property_iv(window, SCREEN_PROPERTY_ZORDER, &topZorder);
Q_SCREEN_CHECKERROR(screen_set_window_property_iv(window, SCREEN_PROPERTY_ZORDER, &topZorder),
"Failed to set window z-order");
topZorder++;
if (result != 0)
qFatal("QQnxWindow: failed to set window z-order=%d, errno=%d, mWindow=%p", topZorder, errno, window);
}
void QQnxWindow::applyWindowState()