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"
40# include "qqnxclipboard.h"
43#if QT_CONFIG(qqnx_imf)
44# include "qqnxinputcontext_imf.h"
49#include <qpa/qplatforminputcontextfactory_p.h>
50#include <qpa/qplatforminputcontext.h>
52#include "private/qgenericunixfontdatabase_p.h"
53#include "private/qgenericunixeventdispatcher_p.h"
55#include <qpa/qplatformwindow.h>
56#include <qpa/qwindowsysteminterface.h>
58#include <QtGui/private/qguiapplication_p.h>
59#include <QtGui/private/qrhibackingstore_p.h>
61#if !defined(QT_NO_OPENGL)
63#include <QtGui/QOpenGLContext>
66#include <private/qsimpledrag_p.h>
68#include <QtCore/QDebug>
69#include <QtCore/QJsonDocument>
70#include <QtCore/QJsonObject>
71#include <QtCore/QJsonArray>
72#include <QtCore/QFile>
77using namespace Qt::StringLiterals;
84 if (!paramList.contains(
"no-fullscreen"_L1)) {
88 if (paramList.contains(
"flush-screen-context"_L1)) {
92 if (paramList.contains(
"rootwindow"_L1)) {
96 if (!paramList.contains(
"disable-EGL_KHR_surfaceless_context"_L1)) {
100 if (paramList.contains(
"desktop"_L1)) {
109 constexpr auto contextCapabilitiesPrefix =
"screen-context-capabilities="_L1;
110 int contextCapabilities = SCREEN_APPLICATION_CONTEXT;
111 for (
const QString ¶m : paramList) {
112 if (param.startsWith(contextCapabilitiesPrefix)) {
113 auto value = QStringView{param}.mid(contextCapabilitiesPrefix.length());
115 contextCapabilities = value.toInt(&ok, 0);
117 contextCapabilities = SCREEN_APPLICATION_CONTEXT;
120 return contextCapabilities;
124 : QPlatformIntegration()
125 , m_screenContextId(256, 0)
126 , m_screenEventThread(0)
128 , m_virtualKeyboard(0)
130#if QT_CONFIG(qqnx_pps)
131 , m_navigatorEventNotifier(0)
132 , m_buttonsNotifier(
new QQnxButtonEventNotifier())
134 , m_qpaInputContext(0)
135 , m_fontDatabase(
new QGenericUnixFontDatabase())
136 , m_eventDispatcher(createUnixEventDispatcher())
138 , m_screenEventHandler(
new QQnxScreenEventHandler(
this))
139#if !defined(QT_NO_CLIPBOARD)
143#if QT_CONFIG(draganddrop)
144 , m_drag(
new QSimpleDrag())
147 , m_eglDisplay(EGL_NO_DISPLAY)
151 m_options = parseOptions(paramList);
152 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
155 if (screen_create_context(&m_screenContext, getContextCapabilities(paramList))) {
156 qFatal(
"%s - Screen: Failed to create screen context - Error: %s (%i)",
157 Q_FUNC_INFO, strerror(errno), errno);
159 screen_get_context_property_cv(m_screenContext,
161 m_screenContextId.size(),
162 m_screenContextId.data());
163 m_screenContextId.resize(strlen(m_screenContextId.constData()));
165#if QT_CONFIG(qqnx_pps)
167 m_navigatorEventNotifier =
new QQnxNavigatorEventNotifier(m_navigatorEventHandler);
171 QMetaObject::invokeMethod(m_navigatorEventNotifier,
"start", Qt::QueuedConnection);
179 m_screenEventThread =
new QQnxScreenEventThread(m_screenContext);
181 m_screenEventThread->start();
183 m_qpaInputContext = QPlatformInputContextFactory::create();
185#if QT_CONFIG(qqnx_pps)
186 if (!m_qpaInputContext) {
188 m_virtualKeyboard =
new QQnxVirtualKeyboardPps();
192 QMetaObject::invokeMethod(m_virtualKeyboard,
"start", Qt::QueuedConnection);
196#if QT_CONFIG(qqnx_pps)
197 m_navigator =
new QQnxNavigatorPps();
202 if (m_virtualKeyboard) {
204 QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(
int)),
205 primaryDisplay(), SLOT(keyboardHeightChanged(
int)));
207#if QT_CONFIG(qqnx_pps)
209 m_inputContext =
new QQnxInputContext(
this, *m_virtualKeyboard);
210#if QT_CONFIG(qqnx_imf)
211 m_screenEventHandler->addScreenEventFilter(m_inputContext);
216#if QT_CONFIG(qqnx_pps)
219 QMetaObject::invokeMethod(m_buttonsNotifier,
"start", Qt::QueuedConnection);
225 qCDebug(lcQpaQnx) <<
"Platform plugin shutdown begin";
226 delete m_nativeInterface;
228#if QT_CONFIG(draganddrop)
233#if !defined(QT_NO_CLIPBOARD)
239#if QT_CONFIG(qqnx_pps)
240 delete m_navigatorEventNotifier;
242 delete m_navigatorEventHandler;
245 delete m_screenEventThread;
248 delete m_eventDispatcher;
250 delete m_screenEventHandler;
256 screen_destroy_context(m_screenContext);
262#if QT_CONFIG(qqnx_pps)
264 delete m_buttonsNotifier;
267 delete m_inputContext;
269 delete m_qpaInputContext;
272 delete m_virtualKeyboard;
280 ms_instance =
nullptr;
282 qCDebug(lcQpaQnx) <<
"Platform plugin shutdown end";
287 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
289 case MultipleWindows:
291 case ThreadedPixmaps:
293#if !defined(QT_NO_OPENGL)
296 case BufferQueueingOpenGL:
300 return QPlatformIntegration::hasCapability(cap);
306 screen_window_t screenWindow =
reinterpret_cast<screen_window_t>(nativeHandle);
307 if (
this->window(screenWindow)) {
308 qWarning() <<
"QWindow already created for foreign window"
313 return new QQnxForeignWindow(window, m_screenContext, screenWindow);
318 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
319 QSurface::SurfaceType surfaceType = window->surfaceType();
320 const bool needRootWindow = options() & RootWindow;
321 switch (surfaceType) {
322 case QSurface::RasterSurface:
323 return new QQnxRasterWindow(window, m_screenContext, needRootWindow);
324#if !defined(QT_NO_OPENGL)
325 case QSurface::OpenGLSurface:
326 return new QQnxEglWindow(window, m_screenContext, needRootWindow);
329 case QSurface::VulkanSurface:
330 return new QQnxVulkanWindow(window, m_screenContext, needRootWindow);
333 qFatal(
"QQnxWindow: unsupported window API");
339QPlatformVulkanInstance *QQnxIntegration::createPlatformVulkanInstance(QVulkanInstance *instance)
const
341 return new QQnxVulkanInstance(instance);
347 QSurface::SurfaceType surfaceType = window->surfaceType();
348 qCDebug(lcQpaQnx) << Q_FUNC_INFO << surfaceType;
349 switch (surfaceType) {
350 case QSurface::RasterSurface:
352#if !defined(QT_NO_OPENGL)
354 case QSurface::OpenGLSurface:
355 return new QRhiBackingStore(window);
358 case QSurface::VulkanSurface:
359 return new QRhiBackingStore(window);
366#if !defined(QT_NO_OPENGL)
367QPlatformOpenGLContext *
QQnxIntegration::createPlatformOpenGLContext(QOpenGLContext *context)
const
369 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
372 QSurfaceFormat format = context->format();
373 int alphaSize = format.alphaBufferSize();
374 int redSize = format.redBufferSize();
375 int greenSize = format.greenBufferSize();
376 int blueSize = format.blueBufferSize();
379 if (alphaSize == -1 && redSize == -1 && greenSize == -1 && blueSize == -1) {
398 if (alphaSize <= 0 && redSize <= 5 && greenSize <= 6 && blueSize <= 5) {
414 format.setAlphaBufferSize(alphaSize);
415 format.setRedBufferSize(redSize);
416 format.setGreenBufferSize(greenSize);
417 format.setBlueBufferSize(blueSize);
418 context->setFormat(format);
427 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
428 if (m_qpaInputContext)
429 return m_qpaInputContext;
430 return m_inputContext;
435 qCDebug(lcQpaQnx) << Q_FUNC_INFO <<
"w =" << window <<
", s =" << screen;
441 QQnxScreen *platformScreen = m_screens.at(screen);
449 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
452 QAbstractEventDispatcher *eventDispatcher = m_eventDispatcher;
453 m_eventDispatcher = 0;
455 return eventDispatcher;
460 return m_nativeInterface;
463#if !defined(QT_NO_CLIPBOARD)
466 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
468#if QT_CONFIG(qqnx_pps)
470 m_clipboard =
new QQnxClipboard;
476#if QT_CONFIG(draganddrop)
477QPlatformDrag *QQnxIntegration::drag()
const
485 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
486 if ((hint == ShowIsFullScreen) && (m_options & FullScreenApplication))
489 return QPlatformIntegration::styleHint(hint);
495 if (m_navigator && !m_services)
503 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
504 QMutexLocker locker(&m_windowMapperMutex);
506 return m_windowMapper.value(qnxWindow, 0);
509void QQnxIntegration::addWindow(screen_window_t qnxWindow, QWindow *window)
511 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
512 QMutexLocker locker(&m_windowMapperMutex);
514 m_windowMapper.insert(qnxWindow, window);
519 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
520 QMutexLocker locker(&m_windowMapperMutex);
522 m_windowMapper.remove(qnxWindow);
526
527
528
529
533 if (screen_get_display_property_iv(display,
542
543
544
545
549 QByteArray json = qgetenv(
"QT_QPA_QNX_DISPLAY_CONFIG");
554 QFile file(QString::fromUtf8(json));
555 if (!file.open(QFile::ReadOnly)) {
556 qWarning() <<
"Could not open config file" << json <<
"for reading";
561 const QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
562 if (!doc.isObject()) {
563 qWarning() <<
"Invalid config file" << json
564 <<
"- no top-level JSON object";
569 const QJsonObject object = doc.object();
570 requestedDisplays = object.value(
"displayOrder"_L1).toArray();
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591QList<screen_display_t *>
QQnxIntegration::sortDisplays(screen_display_t *availableDisplays,
int displayCount)
594 QList<screen_display_t *> allDisplays;
595 for (
int i = 0; i < displayCount; i++)
596 allDisplays.append(&availableDisplays[i]);
599 QJsonArray requestedDisplays;
600 if (!getRequestedDisplays(requestedDisplays))
604 QList<screen_display_t *> orderedDisplays;
605 for (
const QJsonValue &value : std::as_const(requestedDisplays)) {
606 int requestedValue = value.toInt();
610 for (
auto it = allDisplays.begin(), end = allDisplays.end(); it != end; ++it) {
611 screen_display_t *display = *it;
612 if (getIdOfDisplay(*display) == requestedValue) {
613 orderedDisplays.append(display);
614 allDisplays.erase(it);
621 orderedDisplays.append(allDisplays);
623 return orderedDisplays;
628 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
630 int displayCount = 0;
631 int result = screen_get_context_property_iv(m_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT,
635 if (Q_UNLIKELY(displayCount < 1)) {
637 qFatal(
"QQnxIntegration: displayCount=%d", displayCount);
641 screen_display_t *displays = (screen_display_t *)alloca(
sizeof(screen_display_t) * displayCount);
642 result = screen_get_context_property_pv(m_screenContext, SCREEN_PROPERTY_DISPLAYS,
644 QList<screen_display_t *> orderedDisplays = sortDisplays(displays, displayCount);
649 createDisplay(*orderedDisplays[0],
true);
651 for (
int i=1; i<displayCount; i++) {
653 result = screen_get_display_property_iv(*orderedDisplays[i], SCREEN_PROPERTY_ATTACHED,
658 qCDebug(lcQpaQnx) <<
"Skipping non-attached display " << i;
662 qCDebug(lcQpaQnx) <<
"Creating screen for display " << i;
664 createDisplay(*orderedDisplays[i],
false);
670 QQnxScreen *screen =
new QQnxScreen(m_screenContext, display, isPrimary);
671 m_screens.append(screen);
672 QWindowSystemInterface::handleScreenAdded(screen);
675 QObject::connect(m_screenEventHandler, SIGNAL(newWindowCreated(
void*)),
676 screen, SLOT(newWindowCreated(
void*)));
677 QObject::connect(m_screenEventHandler, SIGNAL(windowClosed(
void*)),
678 screen, SLOT(windowClosed(
void*)));
680 QObject::connect(m_navigatorEventHandler, SIGNAL(rotationChanged(
int)), screen, SLOT(setRotation(
int)));
681 QObject::connect(m_navigatorEventHandler, SIGNAL(windowGroupActivated(QByteArray)), screen, SLOT(activateWindowGroup(QByteArray)));
682 QObject::connect(m_navigatorEventHandler, SIGNAL(windowGroupDeactivated(QByteArray)), screen, SLOT(deactivateWindowGroup(QByteArray)));
683 QObject::connect(m_navigatorEventHandler, SIGNAL(windowGroupStateChanged(QByteArray,Qt::WindowState)),
684 screen, SLOT(windowGroupStateChanged(QByteArray,Qt::WindowState)));
690 Q_ASSERT(m_screens.contains(screen));
691 m_screens.removeAll(screen);
692 QWindowSystemInterface::handleScreenRemoved(screen);
697 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
699 Q_FOREACH (QQnxScreen *screen, m_screens) {
700 QWindowSystemInterface::handleScreenRemoved(screen);
707 Q_FOREACH (QQnxScreen *screen, m_screens) {
708 if (screen->nativeDisplay() == qnxScreen)
717 return m_screens.first();
727 return m_screenContext;
732 return m_screenContextId;
737 return m_navigatorEventHandler;
743 return m_navigator != 0;
747void QQnxIntegration::createEglDisplay()
749 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
752 m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
753 if (Q_UNLIKELY(m_eglDisplay == EGL_NO_DISPLAY))
754 qFatal(
"QQnxiIntegration: failed to obtain EGL display: %x", eglGetError());
756 EGLBoolean eglResult = eglInitialize(m_eglDisplay, 0, 0);
757 if (Q_UNLIKELY(eglResult != EGL_TRUE))
758 qFatal(
"QQnxIntegration: failed to initialize EGL display, err=%d", eglGetError());
761void QQnxIntegration::destroyEglDisplay()
763 qCDebug(lcQpaQnx) << Q_FUNC_INFO;
766 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)