22#if !defined(QT_NO_OPENGL)
26#if QT_CONFIG(qqnx_pps)
27#include "qqnxnavigatorpps.h"
28#include "qqnxnavigatoreventnotifier.h"
29#include "qqnxvirtualkeyboardpps.h"
32#if QT_CONFIG(qqnx_pps)
33# include "qqnxbuttoneventnotifier.h"
34# include "qqnxclipboard.h"
37#if QT_CONFIG(qqnx_imf)
38# include "qqnxinputcontext_imf.h"
43#include <qpa/qplatforminputcontextfactory_p.h>
44#include <qpa/qplatforminputcontext.h>
46#include "private/qgenericunixfontdatabase_p.h"
47#include "private/qgenericunixeventdispatcher_p.h"
49#include <qpa/qplatformwindow.h>
50#include <qpa/qwindowsysteminterface.h>
52#include <QtGui/private/qguiapplication_p.h>
53#include <QtGui/private/qrhibackingstore_p.h>
55#if !defined(QT_NO_OPENGL)
57#include <QtGui/QOpenGLContext>
60#include <private/qsimpledrag_p.h>
62#include <QtCore/QDebug>
63#include <QtCore/QJsonDocument>
64#include <QtCore/QJsonObject>
65#include <QtCore/QJsonArray>
66#include <QtCore/QFile>
73using namespace Qt::StringLiterals;
80 if (!paramList.contains(
"no-fullscreen"_L1)) {
84 if (paramList.contains(
"flush-screen-context"_L1)) {
88 if (paramList.contains(
"rootwindow"_L1)) {
92 if (!paramList.contains(
"disable-EGL_KHR_surfaceless_context"_L1)) {
96 if (paramList.contains(
"desktop"_L1)) {
105 constexpr auto contextCapabilitiesPrefix =
"screen-context-capabilities="_L1;
106 int contextCapabilities = SCREEN_APPLICATION_CONTEXT;
107 for (
const QString ¶m : paramList) {
108 if (param.startsWith(contextCapabilitiesPrefix)) {
109 auto value = QStringView{param}.mid(contextCapabilitiesPrefix.length());
111 contextCapabilities = value.toInt(&ok, 0);
113 contextCapabilities = SCREEN_APPLICATION_CONTEXT;
116 return contextCapabilities;
120 : QPlatformIntegration()
121 , m_screenContextId(256, 0)
122 , m_screenEventThread(0)
124 , m_virtualKeyboard(0)
126#if QT_CONFIG(qqnx_pps)
127 , m_navigatorEventNotifier(0)
128 , m_buttonsNotifier(
new QQnxButtonEventNotifier())
130 , m_qpaInputContext(0)
131 , m_fontDatabase(
new QGenericUnixFontDatabase())
132 , m_eventDispatcher(createUnixEventDispatcher())
134 , m_screenEventHandler(
new QQnxScreenEventHandler(
this))
135#if !defined(QT_NO_CLIPBOARD)
139#if QT_CONFIG(draganddrop)
140 , m_drag(
new QSimpleDrag())
143 , m_eglDisplay(EGL_NO_DISPLAY)
147 m_options = parseOptions(paramList);
148 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
151 if (screen_create_context(&m_screenContext, getContextCapabilities(paramList))) {
152 qFatal(
"%s - Screen: Failed to create screen context - Error: %s (%i)",
153 Q_FUNC_INFO, strerror(errno), errno);
155 screen_get_context_property_cv(m_screenContext,
157 m_screenContextId.size(),
158 m_screenContextId.data());
159 m_screenContextId.resize(strlen(m_screenContextId.constData()));
161#if QT_CONFIG(qqnx_pps)
163 m_navigatorEventNotifier =
new QQnxNavigatorEventNotifier(m_navigatorEventHandler);
167 QMetaObject::invokeMethod(m_navigatorEventNotifier,
"start", Qt::QueuedConnection);
175 m_screenEventThread =
new QQnxScreenEventThread(m_screenContext);
177 m_screenEventThread->start();
179 m_qpaInputContext = QPlatformInputContextFactory::create();
181#if QT_CONFIG(qqnx_pps)
182 if (!m_qpaInputContext) {
184 m_virtualKeyboard =
new QQnxVirtualKeyboardPps();
188 QMetaObject::invokeMethod(m_virtualKeyboard,
"start", Qt::QueuedConnection);
192#if QT_CONFIG(qqnx_pps)
193 m_navigator =
new QQnxNavigatorPps();
198 if (m_virtualKeyboard) {
200 QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(
int)),
201 primaryDisplay(), SLOT(keyboardHeightChanged(
int)));
203#if QT_CONFIG(qqnx_pps)
205 m_inputContext =
new QQnxInputContext(
this, *m_virtualKeyboard);
206#if QT_CONFIG(qqnx_imf)
207 m_screenEventHandler->addScreenEventFilter(m_inputContext);
212#if QT_CONFIG(qqnx_pps)
215 QMetaObject::invokeMethod(m_buttonsNotifier,
"start", Qt::QueuedConnection);
221 qCDebug(lcQpaQnx) <<
"Platform plugin shutdown begin";
222 delete m_nativeInterface;
224#if QT_CONFIG(draganddrop)
229#if !defined(QT_NO_CLIPBOARD)
235#if QT_CONFIG(qqnx_pps)
236 delete m_navigatorEventNotifier;
238 delete m_navigatorEventHandler;
241 delete m_screenEventThread;
244 delete m_eventDispatcher;
246 delete m_screenEventHandler;
252 screen_destroy_context(m_screenContext);
258#if QT_CONFIG(qqnx_pps)
260 delete m_buttonsNotifier;
263 delete m_inputContext;
265 delete m_qpaInputContext;
268 delete m_virtualKeyboard;
276 ms_instance =
nullptr;
278 qCDebug(lcQpaQnx) <<
"Platform plugin shutdown end";
283 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
285 case MultipleWindows:
287 case ThreadedPixmaps:
289#if !defined(QT_NO_OPENGL)
292 case BufferQueueingOpenGL:
296 return QPlatformIntegration::hasCapability(cap);
302 screen_window_t screenWindow =
reinterpret_cast<screen_window_t>(nativeHandle);
303 if (
this->window(screenWindow)) {
304 qWarning() <<
"QWindow already created for foreign window"
309 return new QQnxForeignWindow(window, m_screenContext, screenWindow);
314 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
315 QSurface::SurfaceType surfaceType = window->surfaceType();
316 const bool needRootWindow = options() & RootWindow;
317 switch (surfaceType) {
318 case QSurface::RasterSurface:
319 return new QQnxRasterWindow(window, m_screenContext, needRootWindow);
320#if !defined(QT_NO_OPENGL)
321 case QSurface::OpenGLSurface:
322 return new QQnxEglWindow(window, m_screenContext, needRootWindow);
325 qFatal(
"QQnxWindow: unsupported window API");
332 QSurface::SurfaceType surfaceType = window->surfaceType();
333 qCDebug(lcQpaQnx) << Q_FUNC_INFO << surfaceType;
334 switch (surfaceType) {
335 case QSurface::RasterSurface:
337#if !defined(QT_NO_OPENGL)
339 case QSurface::OpenGLSurface:
340 return new QRhiBackingStore(window);
347#if !defined(QT_NO_OPENGL)
348QPlatformOpenGLContext *
QQnxIntegration::createPlatformOpenGLContext(QOpenGLContext *context)
const
350 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
353 QSurfaceFormat format = context->format();
354 int alphaSize = format.alphaBufferSize();
355 int redSize = format.redBufferSize();
356 int greenSize = format.greenBufferSize();
357 int blueSize = format.blueBufferSize();
360 if (alphaSize == -1 && redSize == -1 && greenSize == -1 && blueSize == -1) {
379 if (alphaSize <= 0 && redSize <= 5 && greenSize <= 6 && blueSize <= 5) {
395 format.setAlphaBufferSize(alphaSize);
396 format.setRedBufferSize(redSize);
397 format.setGreenBufferSize(greenSize);
398 format.setBlueBufferSize(blueSize);
399 context->setFormat(format);
408 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
409 if (m_qpaInputContext)
410 return m_qpaInputContext;
411 return m_inputContext;
416 qCDebug(lcQpaQnx) << Q_FUNC_INFO <<
"w =" << window <<
", s =" << screen;
422 QQnxScreen *platformScreen = m_screens.at(screen);
430 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
433 QAbstractEventDispatcher *eventDispatcher = m_eventDispatcher;
434 m_eventDispatcher = 0;
436 return eventDispatcher;
441 return m_nativeInterface;
444#if !defined(QT_NO_CLIPBOARD)
447 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
449#if QT_CONFIG(qqnx_pps)
451 m_clipboard =
new QQnxClipboard;
457#if QT_CONFIG(draganddrop)
458QPlatformDrag *QQnxIntegration::drag()
const
466 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
467 if ((hint == ShowIsFullScreen) && (m_options & FullScreenApplication))
470 return QPlatformIntegration::styleHint(hint);
476 if (m_navigator && !m_services)
484 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
485 QMutexLocker locker(&m_windowMapperMutex);
487 return m_windowMapper.value(qnxWindow, 0);
490void QQnxIntegration::addWindow(screen_window_t qnxWindow, QWindow *window)
492 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
493 QMutexLocker locker(&m_windowMapperMutex);
495 m_windowMapper.insert(qnxWindow, window);
500 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
501 QMutexLocker locker(&m_windowMapperMutex);
503 m_windowMapper.remove(qnxWindow);
507
508
509
510
514 if (screen_get_display_property_iv(display,
523
524
525
526
530 QByteArray json = qgetenv(
"QT_QPA_QNX_DISPLAY_CONFIG");
535 QFile file(QString::fromUtf8(json));
536 if (!file.open(QFile::ReadOnly)) {
537 qWarning() <<
"Could not open config file" << json <<
"for reading";
542 const QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
543 if (!doc.isObject()) {
544 qWarning() <<
"Invalid config file" << json
545 <<
"- no top-level JSON object";
550 const QJsonObject object = doc.object();
551 requestedDisplays = object.value(
"displayOrder"_L1).toArray();
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572QList<screen_display_t *>
QQnxIntegration::sortDisplays(screen_display_t *availableDisplays,
int displayCount)
575 QList<screen_display_t *> allDisplays;
576 for (
int i = 0; i < displayCount; i++)
577 allDisplays.append(&availableDisplays[i]);
580 QJsonArray requestedDisplays;
581 if (!getRequestedDisplays(requestedDisplays))
585 QList<screen_display_t *> orderedDisplays;
586 for (
const QJsonValue &value : std::as_const(requestedDisplays)) {
587 int requestedValue = value.toInt();
591 for (
auto it = allDisplays.begin(), end = allDisplays.end(); it != end; ++it) {
592 screen_display_t *display = *it;
593 if (getIdOfDisplay(*display) == requestedValue) {
594 orderedDisplays.append(display);
595 allDisplays.erase(it);
602 orderedDisplays.append(allDisplays);
604 return orderedDisplays;
609 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
611 int displayCount = 0;
612 int result = screen_get_context_property_iv(m_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT,
616 if (Q_UNLIKELY(displayCount < 1)) {
618 qFatal(
"QQnxIntegration: displayCount=%d", displayCount);
622 screen_display_t *displays = (screen_display_t *)alloca(
sizeof(screen_display_t) * displayCount);
623 result = screen_get_context_property_pv(m_screenContext, SCREEN_PROPERTY_DISPLAYS,
625 QList<screen_display_t *> orderedDisplays = sortDisplays(displays, displayCount);
630 createDisplay(*orderedDisplays[0],
true);
632 for (
int i=1; i<displayCount; i++) {
634 result = screen_get_display_property_iv(*orderedDisplays[i], SCREEN_PROPERTY_ATTACHED,
639 qCDebug(lcQpaQnx) <<
"Skipping non-attached display " << i;
643 qCDebug(lcQpaQnx) <<
"Creating screen for display " << i;
645 createDisplay(*orderedDisplays[i],
false);
651 QQnxScreen *screen =
new QQnxScreen(m_screenContext, display, isPrimary);
652 m_screens.append(screen);
653 QWindowSystemInterface::handleScreenAdded(screen);
656 QObject::connect(m_screenEventHandler, SIGNAL(newWindowCreated(
void*)),
657 screen, SLOT(newWindowCreated(
void*)));
658 QObject::connect(m_screenEventHandler, SIGNAL(windowClosed(
void*)),
659 screen, SLOT(windowClosed(
void*)));
661 QObject::connect(m_navigatorEventHandler, SIGNAL(rotationChanged(
int)), screen, SLOT(setRotation(
int)));
662 QObject::connect(m_navigatorEventHandler, SIGNAL(windowGroupActivated(QByteArray)), screen, SLOT(activateWindowGroup(QByteArray)));
663 QObject::connect(m_navigatorEventHandler, SIGNAL(windowGroupDeactivated(QByteArray)), screen, SLOT(deactivateWindowGroup(QByteArray)));
664 QObject::connect(m_navigatorEventHandler, SIGNAL(windowGroupStateChanged(QByteArray,Qt::WindowState)),
665 screen, SLOT(windowGroupStateChanged(QByteArray,Qt::WindowState)));
671 Q_ASSERT(m_screens.contains(screen));
672 m_screens.removeAll(screen);
673 QWindowSystemInterface::handleScreenRemoved(screen);
678 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
680 Q_FOREACH (QQnxScreen *screen, m_screens) {
681 QWindowSystemInterface::handleScreenRemoved(screen);
688 Q_FOREACH (QQnxScreen *screen, m_screens) {
689 if (screen->nativeDisplay() == qnxScreen)
698 return m_screens.first();
708 return m_screenContext;
713 return m_screenContextId;
718 return m_navigatorEventHandler;
724 return m_navigator != 0;
728void QQnxIntegration::createEglDisplay()
730 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
733 m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
734 if (Q_UNLIKELY(m_eglDisplay == EGL_NO_DISPLAY))
735 qFatal(
"QQnxiIntegration: failed to obtain EGL display: %x", eglGetError());
737 EGLBoolean eglResult = eglInitialize(m_eglDisplay, 0, 0);
738 if (Q_UNLIKELY(eglResult != EGL_TRUE))
739 qFatal(
"QQnxIntegration: failed to initialize EGL display, err=%d", eglGetError());
742void QQnxIntegration::destroyEglDisplay()
744 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
747 eglTerminate(m_eglDisplay);
QAbstractEventDispatcher * createEventDispatcher() const override
Factory function for the GUI event dispatcher.
bool hasCapability(QPlatformIntegration::Capability cap) const override
QPlatformNativeInterface * nativeInterface() const override
QQnxNavigatorEventHandler * navigatorEventHandler()
@ AlwaysFlushScreenContext
QPlatformBackingStore * createPlatformBackingStore(QWindow *window) const override
Factory function for QPlatformBackingStore.
QPlatformWindow * createPlatformWindow(QWindow *window) const override
Factory function for QPlatformWindow.
QPlatformWindow * createForeignWindow(QWindow *window, WId nativeHandle) const override
QQnxScreen * primaryDisplay() const
void removeDisplay(QQnxScreen *screen)
QVariant styleHint(StyleHint hint) const override
QPlatformServices * services() const override
void moveToScreen(QWindow *window, int screen)
QPlatformInputContext * inputContext() const override
Returns the platforms input context.
QByteArray screenContextId()
QQnxScreen * screenForNative(screen_display_t qnxScreen) const
void createDisplay(screen_display_t display, bool isPrimary)
screen_context_t screenContext()
QWindow * window(screen_window_t qnxWindow) const
QPlatformClipboard * clipboard() const override
Accessor for the platform integration's clipboard.
bool supportsNavigatorEvents() const
QQnxNativeInterface(QQnxIntegration *integration)
void setScreenEventThread(QQnxScreenEventThread *eventThread)
int depth() const override
Reimplement in subclass to return current depth of the screen.
QQnxServices(QQnxAbstractNavigator *navigator)
The QQnxWindow is the base class of the various classes used as instances of QPlatformWindow in the Q...
void setScreen(QQnxScreen *platformScreen)
#define Q_SCREEN_CRITICALERROR(x, message)
#define Q_SCREEN_CHECKERROR(x, message)
static bool getRequestedDisplays(QJsonArray &requestedDisplays)
Read JSON configuration file for the QNX display order.
static int getIdOfDisplay(screen_display_t display)
Get display ID for given display.
static int getContextCapabilities(const QStringList ¶mList)
static QQnxIntegration::Options parseOptions(const QStringList ¶mList)