23#if !defined(QT_NO_OPENGL)
28#include "qqnxvulkanwindow.h"
29#include "qqnxvulkaninstance.h"
32#if QT_CONFIG(qqnx_pps)
33#include "qqnxnavigatorpps.h"
34#include "qqnxnavigatoreventnotifier.h"
35#include "qqnxvirtualkeyboardpps.h"
38#if QT_CONFIG(qqnx_pps)
39# include "qqnxbuttoneventnotifier.h"
42#if QT_CONFIG(qqnx_imf)
43# include "qqnxinputcontext_imf.h"
48#if !defined(QT_NO_CLIPBOARD)
52#include <qpa/qplatforminputcontextfactory_p.h>
53#include <qpa/qplatforminputcontext.h>
55#include "private/qgenericunixfontdatabase_p.h"
56#include "private/qgenericunixeventdispatcher_p.h"
58#include <qpa/qplatformwindow.h>
59#include <qpa/qwindowsysteminterface.h>
61#include <QtGui/private/qguiapplication_p.h>
62#include <QtGui/private/qrhibackingstore_p.h>
64#if !defined(QT_NO_OPENGL)
66#include <QtGui/QOpenGLContext>
69#include <private/qsimpledrag_p.h>
71#include <QtCore/QDebug>
72#include <QtCore/QJsonDocument>
73#include <QtCore/QJsonObject>
74#include <QtCore/QJsonArray>
75#include <QtCore/QFile>
80using namespace Qt::StringLiterals;
87 if (!paramList.contains(
"no-fullscreen"_L1)) {
91 if (paramList.contains(
"flush-screen-context"_L1)) {
95 if (paramList.contains(
"rootwindow"_L1)) {
99 if (!paramList.contains(
"disable-EGL_KHR_surfaceless_context"_L1)) {
103 if (paramList.contains(
"desktop"_L1)) {
112 constexpr auto contextCapabilitiesPrefix =
"screen-context-capabilities="_L1;
113 int contextCapabilities = SCREEN_APPLICATION_CONTEXT;
114 for (
const QString ¶m : paramList) {
115 if (param.startsWith(contextCapabilitiesPrefix)) {
116 auto value = QStringView{param}.mid(contextCapabilitiesPrefix.length());
118 contextCapabilities = value.toInt(&ok, 0);
120 contextCapabilities = SCREEN_APPLICATION_CONTEXT;
123 return contextCapabilities;
127 : QPlatformIntegration()
128 , m_screenContextId(256, 0)
129 , m_screenEventThread(0)
131 , m_virtualKeyboard(0)
133#if QT_CONFIG(qqnx_pps)
134 , m_navigatorEventNotifier(0)
135 , m_buttonsNotifier(
new QQnxButtonEventNotifier())
137 , m_qpaInputContext(0)
138 , m_fontDatabase(
new QGenericUnixFontDatabase())
139 , m_eventDispatcher(createUnixEventDispatcher())
141 , m_screenEventHandler(
new QQnxScreenEventHandler(
this))
142#if !defined(QT_NO_CLIPBOARD)
146#if QT_CONFIG(draganddrop)
147 , m_drag(
new QSimpleDrag())
150 , m_eglDisplay(EGL_NO_DISPLAY)
154 m_options = parseOptions(paramList);
155 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
158 if (screen_create_context(&m_screenContext, getContextCapabilities(paramList))) {
159 qFatal(
"%s - Screen: Failed to create screen context - Error: %s (%i)",
160 Q_FUNC_INFO, strerror(errno), errno);
162 screen_get_context_property_cv(m_screenContext,
164 m_screenContextId.size(),
165 m_screenContextId.data());
166 m_screenContextId.resize(strlen(m_screenContextId.constData()));
168#if QT_CONFIG(qqnx_pps)
170 m_navigatorEventNotifier =
new QQnxNavigatorEventNotifier(m_navigatorEventHandler);
174 QMetaObject::invokeMethod(m_navigatorEventNotifier,
"start", Qt::QueuedConnection);
182 m_screenEventThread =
new QQnxScreenEventThread(m_screenContext);
184 m_screenEventThread->start();
186 m_qpaInputContext = QPlatformInputContextFactory::create();
188#if QT_CONFIG(qqnx_pps)
189 if (!m_qpaInputContext) {
191 m_virtualKeyboard =
new QQnxVirtualKeyboardPps();
195 QMetaObject::invokeMethod(m_virtualKeyboard,
"start", Qt::QueuedConnection);
199#if QT_CONFIG(qqnx_pps)
200 m_navigator =
new QQnxNavigatorPps();
205 if (m_virtualKeyboard) {
207 QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(
int)),
208 primaryDisplay(), SLOT(keyboardHeightChanged(
int)));
210#if QT_CONFIG(qqnx_pps)
212 m_inputContext =
new QQnxInputContext(
this, *m_virtualKeyboard);
213#if QT_CONFIG(qqnx_imf)
214 m_screenEventHandler->addScreenEventFilter(m_inputContext);
219#if QT_CONFIG(qqnx_pps)
222 QMetaObject::invokeMethod(m_buttonsNotifier,
"start", Qt::QueuedConnection);
228 qCDebug(lcQpaQnx) <<
"Platform plugin shutdown begin";
229 delete m_nativeInterface;
231#if QT_CONFIG(draganddrop)
236#if !defined(QT_NO_CLIPBOARD)
242#if QT_CONFIG(qqnx_pps)
243 delete m_navigatorEventNotifier;
245 delete m_navigatorEventHandler;
248 delete m_screenEventThread;
251 delete m_eventDispatcher;
253 delete m_screenEventHandler;
259 screen_destroy_context(m_screenContext);
265#if QT_CONFIG(qqnx_pps)
267 delete m_buttonsNotifier;
270 delete m_inputContext;
272 delete m_qpaInputContext;
275 delete m_virtualKeyboard;
283 ms_instance =
nullptr;
285 qCDebug(lcQpaQnx) <<
"Platform plugin shutdown end";
290 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
292 case MultipleWindows:
294 case ThreadedPixmaps:
296#if !defined(QT_NO_OPENGL)
299 case BufferQueueingOpenGL:
303 return QPlatformIntegration::hasCapability(cap);
309 screen_window_t screenWindow =
reinterpret_cast<screen_window_t>(nativeHandle);
310 if (
this->window(screenWindow)) {
311 qWarning() <<
"QWindow already created for foreign window"
316 return new QQnxForeignWindow(window, m_screenContext, screenWindow);
321 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
322 QSurface::SurfaceType surfaceType = window->surfaceType();
323 const bool needRootWindow = options() & RootWindow;
324 switch (surfaceType) {
325 case QSurface::RasterSurface:
326 return new QQnxRasterWindow(window, m_screenContext, needRootWindow);
327#if !defined(QT_NO_OPENGL)
328 case QSurface::OpenGLSurface:
329 return new QQnxEglWindow(window, m_screenContext, needRootWindow);
332 case QSurface::VulkanSurface:
333 return new QQnxVulkanWindow(window, m_screenContext, needRootWindow);
336 qFatal(
"QQnxWindow: unsupported window API");
342QPlatformVulkanInstance *QQnxIntegration::createPlatformVulkanInstance(QVulkanInstance *instance)
const
344 return new QQnxVulkanInstance(instance);
350 QSurface::SurfaceType surfaceType = window->surfaceType();
351 qCDebug(lcQpaQnx) << Q_FUNC_INFO << surfaceType;
352 switch (surfaceType) {
353 case QSurface::RasterSurface:
355#if !defined(QT_NO_OPENGL)
357 case QSurface::OpenGLSurface:
358 return new QRhiBackingStore(window);
361 case QSurface::VulkanSurface:
362 return new QRhiBackingStore(window);
369#if !defined(QT_NO_OPENGL)
370QPlatformOpenGLContext *
QQnxIntegration::createPlatformOpenGLContext(QOpenGLContext *context)
const
372 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
375 QSurfaceFormat format = context->format();
376 int alphaSize = format.alphaBufferSize();
377 int redSize = format.redBufferSize();
378 int greenSize = format.greenBufferSize();
379 int blueSize = format.blueBufferSize();
382 if (alphaSize == -1 && redSize == -1 && greenSize == -1 && blueSize == -1) {
401 if (alphaSize <= 0 && redSize <= 5 && greenSize <= 6 && blueSize <= 5) {
417 format.setAlphaBufferSize(alphaSize);
418 format.setRedBufferSize(redSize);
419 format.setGreenBufferSize(greenSize);
420 format.setBlueBufferSize(blueSize);
421 context->setFormat(format);
430 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
431 if (m_qpaInputContext)
432 return m_qpaInputContext;
433 return m_inputContext;
438 qCDebug(lcQpaQnx) << Q_FUNC_INFO <<
"w =" << window <<
", s =" << screen;
444 QQnxScreen *platformScreen = m_screens.at(screen);
452 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
455 QAbstractEventDispatcher *eventDispatcher = m_eventDispatcher;
456 m_eventDispatcher = 0;
458 return eventDispatcher;
463 return m_nativeInterface;
466#if !defined(QT_NO_CLIPBOARD)
469 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
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)