22#if !defined(QT_NO_OPENGL)
27#include "qqnxvulkanwindow.h"
28#include "qqnxvulkaninstance.h"
31#if QT_CONFIG(qqnx_pps)
32#include "qqnxnavigatorpps.h"
33#include "qqnxnavigatoreventnotifier.h"
34#include "qqnxvirtualkeyboardpps.h"
37#if QT_CONFIG(qqnx_pps)
38# include "qqnxbuttoneventnotifier.h"
39# include "qqnxclipboard.h"
42#if QT_CONFIG(qqnx_imf)
43# include "qqnxinputcontext_imf.h"
48#include <qpa/qplatforminputcontextfactory_p.h>
49#include <qpa/qplatforminputcontext.h>
51#include "private/qgenericunixfontdatabase_p.h"
52#include "private/qgenericunixeventdispatcher_p.h"
54#include <qpa/qplatformwindow.h>
55#include <qpa/qwindowsysteminterface.h>
57#include <QtGui/private/qguiapplication_p.h>
58#include <QtGui/private/qrhibackingstore_p.h>
60#if !defined(QT_NO_OPENGL)
62#include <QtGui/QOpenGLContext>
65#include <private/qsimpledrag_p.h>
67#include <QtCore/QDebug>
68#include <QtCore/QJsonDocument>
69#include <QtCore/QJsonObject>
70#include <QtCore/QJsonArray>
71#include <QtCore/QFile>
78using namespace Qt::StringLiterals;
85 if (!paramList.contains(
"no-fullscreen"_L1)) {
89 if (paramList.contains(
"flush-screen-context"_L1)) {
93 if (paramList.contains(
"rootwindow"_L1)) {
97 if (!paramList.contains(
"disable-EGL_KHR_surfaceless_context"_L1)) {
101 if (paramList.contains(
"desktop"_L1)) {
110 constexpr auto contextCapabilitiesPrefix =
"screen-context-capabilities="_L1;
111 int contextCapabilities = SCREEN_APPLICATION_CONTEXT;
112 for (
const QString ¶m : paramList) {
113 if (param.startsWith(contextCapabilitiesPrefix)) {
114 auto value = QStringView{param}.mid(contextCapabilitiesPrefix.length());
116 contextCapabilities = value.toInt(&ok, 0);
118 contextCapabilities = SCREEN_APPLICATION_CONTEXT;
121 return contextCapabilities;
125 : QPlatformIntegration()
126 , m_screenContextId(256, 0)
127 , m_screenEventThread(0)
129 , m_virtualKeyboard(0)
131#if QT_CONFIG(qqnx_pps)
132 , m_navigatorEventNotifier(0)
133 , m_buttonsNotifier(
new QQnxButtonEventNotifier())
135 , m_qpaInputContext(0)
136 , m_fontDatabase(
new QGenericUnixFontDatabase())
137 , m_eventDispatcher(createUnixEventDispatcher())
139 , m_screenEventHandler(
new QQnxScreenEventHandler(
this))
140#if !defined(QT_NO_CLIPBOARD)
144#if QT_CONFIG(draganddrop)
145 , m_drag(
new QSimpleDrag())
148 , m_eglDisplay(EGL_NO_DISPLAY)
152 m_options = parseOptions(paramList);
153 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
156 if (screen_create_context(&m_screenContext, getContextCapabilities(paramList))) {
157 qFatal(
"%s - Screen: Failed to create screen context - Error: %s (%i)",
158 Q_FUNC_INFO, strerror(errno), errno);
160 screen_get_context_property_cv(m_screenContext,
162 m_screenContextId.size(),
163 m_screenContextId.data());
164 m_screenContextId.resize(strlen(m_screenContextId.constData()));
166#if QT_CONFIG(qqnx_pps)
168 m_navigatorEventNotifier =
new QQnxNavigatorEventNotifier(m_navigatorEventHandler);
172 QMetaObject::invokeMethod(m_navigatorEventNotifier,
"start", Qt::QueuedConnection);
180 m_screenEventThread =
new QQnxScreenEventThread(m_screenContext);
182 m_screenEventThread->start();
184 m_qpaInputContext = QPlatformInputContextFactory::create();
186#if QT_CONFIG(qqnx_pps)
187 if (!m_qpaInputContext) {
189 m_virtualKeyboard =
new QQnxVirtualKeyboardPps();
193 QMetaObject::invokeMethod(m_virtualKeyboard,
"start", Qt::QueuedConnection);
197#if QT_CONFIG(qqnx_pps)
198 m_navigator =
new QQnxNavigatorPps();
203 if (m_virtualKeyboard) {
205 QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(
int)),
206 primaryDisplay(), SLOT(keyboardHeightChanged(
int)));
208#if QT_CONFIG(qqnx_pps)
210 m_inputContext =
new QQnxInputContext(
this, *m_virtualKeyboard);
211#if QT_CONFIG(qqnx_imf)
212 m_screenEventHandler->addScreenEventFilter(m_inputContext);
217#if QT_CONFIG(qqnx_pps)
220 QMetaObject::invokeMethod(m_buttonsNotifier,
"start", Qt::QueuedConnection);
226 qCDebug(lcQpaQnx) <<
"Platform plugin shutdown begin";
227 delete m_nativeInterface;
229#if QT_CONFIG(draganddrop)
234#if !defined(QT_NO_CLIPBOARD)
240#if QT_CONFIG(qqnx_pps)
241 delete m_navigatorEventNotifier;
243 delete m_navigatorEventHandler;
246 delete m_screenEventThread;
249 delete m_eventDispatcher;
251 delete m_screenEventHandler;
257 screen_destroy_context(m_screenContext);
263#if QT_CONFIG(qqnx_pps)
265 delete m_buttonsNotifier;
268 delete m_inputContext;
270 delete m_qpaInputContext;
273 delete m_virtualKeyboard;
281 ms_instance =
nullptr;
283 qCDebug(lcQpaQnx) <<
"Platform plugin shutdown end";
288 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
290 case MultipleWindows:
292 case ThreadedPixmaps:
294#if !defined(QT_NO_OPENGL)
297 case BufferQueueingOpenGL:
301 return QPlatformIntegration::hasCapability(cap);
307 screen_window_t screenWindow =
reinterpret_cast<screen_window_t>(nativeHandle);
308 if (
this->window(screenWindow)) {
309 qWarning() <<
"QWindow already created for foreign window"
314 return new QQnxForeignWindow(window, m_screenContext, screenWindow);
319 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
320 QSurface::SurfaceType surfaceType = window->surfaceType();
321 const bool needRootWindow = options() & RootWindow;
322 switch (surfaceType) {
323 case QSurface::RasterSurface:
324 return new QQnxRasterWindow(window, m_screenContext, needRootWindow);
325#if !defined(QT_NO_OPENGL)
326 case QSurface::OpenGLSurface:
327 return new QQnxEglWindow(window, m_screenContext, needRootWindow);
330 case QSurface::VulkanSurface:
331 return new QQnxVulkanWindow(window, m_screenContext, needRootWindow);
334 qFatal(
"QQnxWindow: unsupported window API");
340QPlatformVulkanInstance *QQnxIntegration::createPlatformVulkanInstance(QVulkanInstance *instance)
const
342 return new QQnxVulkanInstance(instance);
348 QSurface::SurfaceType surfaceType = window->surfaceType();
349 qCDebug(lcQpaQnx) << Q_FUNC_INFO << surfaceType;
350 switch (surfaceType) {
351 case QSurface::RasterSurface:
353#if !defined(QT_NO_OPENGL)
355 case QSurface::OpenGLSurface:
356 return new QRhiBackingStore(window);
359 case QSurface::VulkanSurface:
360 return new QRhiBackingStore(window);
367#if !defined(QT_NO_OPENGL)
368QPlatformOpenGLContext *
QQnxIntegration::createPlatformOpenGLContext(QOpenGLContext *context)
const
370 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
373 QSurfaceFormat format = context->format();
374 int alphaSize = format.alphaBufferSize();
375 int redSize = format.redBufferSize();
376 int greenSize = format.greenBufferSize();
377 int blueSize = format.blueBufferSize();
380 if (alphaSize == -1 && redSize == -1 && greenSize == -1 && blueSize == -1) {
399 if (alphaSize <= 0 && redSize <= 5 && greenSize <= 6 && blueSize <= 5) {
415 format.setAlphaBufferSize(alphaSize);
416 format.setRedBufferSize(redSize);
417 format.setGreenBufferSize(greenSize);
418 format.setBlueBufferSize(blueSize);
419 context->setFormat(format);
428 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
429 if (m_qpaInputContext)
430 return m_qpaInputContext;
431 return m_inputContext;
436 qCDebug(lcQpaQnx) << Q_FUNC_INFO <<
"w =" << window <<
", s =" << screen;
442 QQnxScreen *platformScreen = m_screens.at(screen);
450 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
453 QAbstractEventDispatcher *eventDispatcher = m_eventDispatcher;
454 m_eventDispatcher = 0;
456 return eventDispatcher;
461 return m_nativeInterface;
464#if !defined(QT_NO_CLIPBOARD)
467 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
469#if QT_CONFIG(qqnx_pps)
471 m_clipboard =
new QQnxClipboard;
477#if QT_CONFIG(draganddrop)
478QPlatformDrag *QQnxIntegration::drag()
const
486 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
487 if ((hint == ShowIsFullScreen) && (m_options & FullScreenApplication))
490 return QPlatformIntegration::styleHint(hint);
496 if (m_navigator && !m_services)
504 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
505 QMutexLocker locker(&m_windowMapperMutex);
507 return m_windowMapper.value(qnxWindow, 0);
510void QQnxIntegration::addWindow(screen_window_t qnxWindow, QWindow *window)
512 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
513 QMutexLocker locker(&m_windowMapperMutex);
515 m_windowMapper.insert(qnxWindow, window);
520 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
521 QMutexLocker locker(&m_windowMapperMutex);
523 m_windowMapper.remove(qnxWindow);
527
528
529
530
534 if (screen_get_display_property_iv(display,
543
544
545
546
550 QByteArray json = qgetenv(
"QT_QPA_QNX_DISPLAY_CONFIG");
555 QFile file(QString::fromUtf8(json));
556 if (!file.open(QFile::ReadOnly)) {
557 qWarning() <<
"Could not open config file" << json <<
"for reading";
562 const QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
563 if (!doc.isObject()) {
564 qWarning() <<
"Invalid config file" << json
565 <<
"- no top-level JSON object";
570 const QJsonObject object = doc.object();
571 requestedDisplays = object.value(
"displayOrder"_L1).toArray();
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592QList<screen_display_t *>
QQnxIntegration::sortDisplays(screen_display_t *availableDisplays,
int displayCount)
595 QList<screen_display_t *> allDisplays;
596 for (
int i = 0; i < displayCount; i++)
597 allDisplays.append(&availableDisplays[i]);
600 QJsonArray requestedDisplays;
601 if (!getRequestedDisplays(requestedDisplays))
605 QList<screen_display_t *> orderedDisplays;
606 for (
const QJsonValue &value : std::as_const(requestedDisplays)) {
607 int requestedValue = value.toInt();
611 for (
auto it = allDisplays.begin(), end = allDisplays.end(); it != end; ++it) {
612 screen_display_t *display = *it;
613 if (getIdOfDisplay(*display) == requestedValue) {
614 orderedDisplays.append(display);
615 allDisplays.erase(it);
622 orderedDisplays.append(allDisplays);
624 return orderedDisplays;
629 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
631 int displayCount = 0;
632 int result = screen_get_context_property_iv(m_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT,
636 if (Q_UNLIKELY(displayCount < 1)) {
638 qFatal(
"QQnxIntegration: displayCount=%d", displayCount);
642 screen_display_t *displays = (screen_display_t *)alloca(
sizeof(screen_display_t) * displayCount);
643 result = screen_get_context_property_pv(m_screenContext, SCREEN_PROPERTY_DISPLAYS,
645 QList<screen_display_t *> orderedDisplays = sortDisplays(displays, displayCount);
650 createDisplay(*orderedDisplays[0],
true);
652 for (
int i=1; i<displayCount; i++) {
654 result = screen_get_display_property_iv(*orderedDisplays[i], SCREEN_PROPERTY_ATTACHED,
659 qCDebug(lcQpaQnx) <<
"Skipping non-attached display " << i;
663 qCDebug(lcQpaQnx) <<
"Creating screen for display " << i;
665 createDisplay(*orderedDisplays[i],
false);
671 QQnxScreen *screen =
new QQnxScreen(m_screenContext, display, isPrimary);
672 m_screens.append(screen);
673 QWindowSystemInterface::handleScreenAdded(screen);
676 QObject::connect(m_screenEventHandler, SIGNAL(newWindowCreated(
void*)),
677 screen, SLOT(newWindowCreated(
void*)));
678 QObject::connect(m_screenEventHandler, SIGNAL(windowClosed(
void*)),
679 screen, SLOT(windowClosed(
void*)));
681 QObject::connect(m_navigatorEventHandler, SIGNAL(rotationChanged(
int)), screen, SLOT(setRotation(
int)));
682 QObject::connect(m_navigatorEventHandler, SIGNAL(windowGroupActivated(QByteArray)), screen, SLOT(activateWindowGroup(QByteArray)));
683 QObject::connect(m_navigatorEventHandler, SIGNAL(windowGroupDeactivated(QByteArray)), screen, SLOT(deactivateWindowGroup(QByteArray)));
684 QObject::connect(m_navigatorEventHandler, SIGNAL(windowGroupStateChanged(QByteArray,Qt::WindowState)),
685 screen, SLOT(windowGroupStateChanged(QByteArray,Qt::WindowState)));
691 Q_ASSERT(m_screens.contains(screen));
692 m_screens.removeAll(screen);
693 QWindowSystemInterface::handleScreenRemoved(screen);
698 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
700 Q_FOREACH (QQnxScreen *screen, m_screens) {
701 QWindowSystemInterface::handleScreenRemoved(screen);
708 Q_FOREACH (QQnxScreen *screen, m_screens) {
709 if (screen->nativeDisplay() == qnxScreen)
718 return m_screens.first();
728 return m_screenContext;
733 return m_screenContextId;
738 return m_navigatorEventHandler;
744 return m_navigator != 0;
748void QQnxIntegration::createEglDisplay()
750 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
753 m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
754 if (Q_UNLIKELY(m_eglDisplay == EGL_NO_DISPLAY))
755 qFatal(
"QQnxiIntegration: failed to obtain EGL display: %x", eglGetError());
757 EGLBoolean eglResult = eglInitialize(m_eglDisplay, 0, 0);
758 if (Q_UNLIKELY(eglResult != EGL_TRUE))
759 qFatal(
"QQnxIntegration: failed to initialize EGL display, err=%d", eglGetError());
762void QQnxIntegration::destroyEglDisplay()
764 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
767 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)