QQnxBuffer::QQnxBuffer(screen_buffer_t buffer) : m_buffer(buffer) { qBufferDebug() << Q_FUNC_INFO << "normal"; // Get size of buffer int size[2]; Q_SCREEN_CRITICALERROR(screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_BUFFER_SIZE, size), "Failed to query buffer size"); // Get stride of buffer int stride; 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; 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 int screenFormat; 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; switch (screenFormat) { case SCREEN_FORMAT_RGBX4444: imageFormat = QImage::Format_RGB444; break; case SCREEN_FORMAT_RGBA4444: imageFormat = QImage::Format_ARGB4444_Premultiplied; break; case SCREEN_FORMAT_RGBX5551: imageFormat = QImage::Format_RGB555; break; case SCREEN_FORMAT_RGB565: imageFormat = QImage::Format_RGB16; break; case SCREEN_FORMAT_RGBX8888: imageFormat = QImage::Format_RGB32; break; case SCREEN_FORMAT_RGBA8888: imageFormat = QImage::Format_ARGB32_Premultiplied; break; default: qFatal("QQNX: unsupported buffer format, format=%d", screenFormat); } // wrap buffer in an image m_image = QImage(dataPtr, size[0], size[1], stride, imageFormat); }
QQnxBuffer &QQnxRasterWindow::renderBuffer() { qRasterWindowDebug() << Q_FUNC_INFO << "window =" << window(); // Check if render buffer is invalid if (m_currentBufferIndex == -1) { // Get all buffers available for rendering screen_buffer_t buffers[MAX_BUFFER_COUNT]; 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 int bg[] = { SCREEN_BLIT_COLOR, 0x00000000, SCREEN_BLIT_END }; Q_SCREEN_CHECKERROR(screen_fill(screen()->nativeContext(), buffers[i], bg), "Failed to clear window buffer"); } Q_SCREEN_CHECKERROR(screen_flush_blits(screen()->nativeContext(), 0), "Failed to flush blits"); // Use the first available render buffer m_currentBufferIndex = 0; m_previousBufferIndex = -1; } return m_buffers[m_currentBufferIndex]; }
void QQnxIntegration::createDisplays() { qIntegrationDebug() << Q_FUNC_INFO; // Query number of displays 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 qFatal("QQnxIntegration: displayCount=%d", displayCount); } // Get all displays screen_display_t *displays = (screen_display_t *)alloca(sizeof(screen_display_t) * displayCount); 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 = 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; continue; } qIntegrationDebug() << Q_FUNC_INFO << "Creating screen for display" << i; createDisplay(displays[i], /*isPrimary=*/false); } // of displays iteration }
QQnxIntegration::QQnxIntegration(const QStringList ¶mList) : QPlatformIntegration() #if defined(QQNX_SCREENEVENTTHREAD) , m_screenEventThread(0) #endif , m_navigatorEventHandler(new QQnxNavigatorEventHandler()) , m_virtualKeyboard(0) #if defined(QQNX_PPS) , m_navigatorEventNotifier(0) , m_inputContext(0) , m_buttonsNotifier(new QQnxButtonEventNotifier()) #endif , m_services(0) , m_fontDatabase(new QGenericUnixFontDatabase()) #if defined(Q_OS_BLACKBERRY) , m_eventDispatcher(new QQnxEventDispatcherBlackberry()) , m_bpsEventFilter(0) #else , m_eventDispatcher(createUnixEventDispatcher()) #endif , m_nativeInterface(new QQnxNativeInterface(this)) , m_screenEventHandler(new QQnxScreenEventHandler(this)) #if !defined(QT_NO_CLIPBOARD) , m_clipboard(0) #endif , m_navigator(0) #if !defined(QT_NO_DRAGANDDROP) , m_drag(new QSimpleDrag()) #endif { ms_options = parseOptions(paramList); qIntegrationDebug() << Q_FUNC_INFO; // Open connection to QNX composition manager 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) // Create/start navigator event notifier m_navigatorEventNotifier = new QQnxNavigatorEventNotifier(m_navigatorEventHandler); // delay invocation of start() to the time the event loop is up and running // needed to have the QThread internals of the main thread properly initialized QMetaObject::invokeMethod(m_navigatorEventNotifier, "start", Qt::QueuedConnection); #endif #if !defined(QT_NO_OPENGL) // Initialize global OpenGL resources QQnxGLContext::initialize(); #endif // Create/start event thread #if defined(QQNX_SCREENEVENTTHREAD) m_screenEventThread = new QQnxScreenEventThread(ms_screenContext, m_screenEventHandler); m_screenEventThread->start(); #endif // Not on BlackBerry, it has specialized event dispatcher which also handles virtual keyboard events #if !defined(Q_OS_BLACKBERRY) && defined(QQNX_PPS) // Create/start the keyboard class. m_virtualKeyboard = new QQnxVirtualKeyboardPps(); // delay invocation of start() to the time the event loop is up and running // needed to have the QThread internals of the main thread properly initialized QMetaObject::invokeMethod(m_virtualKeyboard, "start", Qt::QueuedConnection); #endif #if defined(Q_OS_BLACKBERRY) m_navigator = new QQnxNavigatorBps(); #elif defined(QQNX_PPS) m_navigator = new QQnxNavigatorPps(); #endif // Create services handling class if (m_navigator) m_services = new QQnxServices(m_navigator); #if defined(Q_OS_BLACKBERRY) QQnxVirtualKeyboardBps* virtualKeyboardBps = new QQnxVirtualKeyboardBps; #if defined(QQNX_SCREENEVENTTHREAD) m_bpsEventFilter = new QQnxBpsEventFilter(m_navigatorEventHandler, 0, virtualKeyboardBps); #else m_bpsEventFilter = new QQnxBpsEventFilter(m_navigatorEventHandler, m_screenEventHandler, virtualKeyboardBps); #endif m_bpsEventFilter->installOnEventDispatcher(m_eventDispatcher); m_virtualKeyboard = virtualKeyboardBps; #endif // Create displays for all possible screens (which may not be attached). We have to do this // *after* the call to m_bpsEventFilter->installOnEventDispatcher(m_eventDispatcher). The // reason for this is that we have to be registered for NAVIGATOR events before we create the // QQnxScreen objects, and hence the QQnxRootWindow's. It is when the NAVIGATOR service sees // the window creation that it starts sending us messages which results in a race if we // create the displays first. createDisplays(); #if !defined(QQNX_SCREENEVENTTHREAD) && defined(Q_OS_BLACKBERRY) // Register for screen domain events with bps Q_FOREACH (QQnxScreen *screen, m_screens) m_bpsEventFilter->registerForScreenEvents(screen); #endif if (m_virtualKeyboard) { // TODO check if we need to do this for all screens or only the primary one QObject::connect(m_virtualKeyboard, SIGNAL(heightChanged(int)), primaryDisplay(), SLOT(keyboardHeightChanged(int))); #if defined(QQNX_PPS) // Set up the input context m_inputContext = new QQnxInputContext(this, *m_virtualKeyboard); #if defined(QQNX_IMF) m_screenEventHandler->addScreenEventFilter(m_inputContext); #endif #endif } #if defined(QQNX_PPS) // delay invocation of start() to the time the event loop is up and running // needed to have the QThread internals of the main thread properly initialized QMetaObject::invokeMethod(m_buttonsNotifier, "start", Qt::QueuedConnection); #endif }
QT_BEGIN_NAMESPACE /*! \class QQnxWindow \brief The QQnxWindow is the base class of the various classes used as instances of QPlatformWindow in the QNX QPA plugin. The standard properties and methods available in Qt are not a perfect match for the features provided by the QNX screen service. While for the majority of applications the default behavior suffices, some circumstances require greater control over the interaction with screen. \section1 Window Types The QNX QPA plugin can operate in two modes, with or without a root window. The selection of mode is made via the \e rootwindow and \e no-rootwindow options to the plugin. The default mode is rootwindow for BlackBerry builds and no-rootwindow for non-BlackBerry builds. Windows with parents are always created as child windows, the difference in the modes is in the treatment of parentless windows. In no-rootwindow mode, these windows are created as application windows while in rootwindow mode, the first window on a screen is created as an application window while subsequent windows are created as child windows. The only exception to this is any window of type Qt::Desktop or Qt::CoverWindow; these are created as application windows, but will never become the root window, even if they are the first window created. It is also possible to create a parentless child window. These may be useful to create windows that are parented by windows from other processes. To do this, you attach a dynamic property \e qnxInitialWindowGroup to the QWindow though this must be done prior to the platform window class (this class) being created which typically happens when the window is made visible. When the window is created in QML, it is acceptable to have the \e visible property hardcoded to true so long as the qnxInitialWindowGroup is also set. \section1 Joining Window Groups Window groups may be joined in a number of ways, some are automatic based on predefined rules though an application is also able to provide explicit control. A QWindow that has a parent will join its parent's window group. When rootwindow mode is in effect, all but the first parentless window on a screen will be child windows and join the window group of the first parentless window, the root window. If a QWindow has a valid dynamic property called \e qnxInitialWindowGroup at the time the QQnxWindow is created, the window will be created as a child window and, if the qnxInitialWindowGroup property is a non-empty string, an attempt will be made to join that window group. This has an effect only when the QQnxWindow is created, subsequent changes to this property are ignored. Setting the property to an empty string provides a means to create 'top level' child windows without automatically joining any group. Typically when this property is used \e qnxWindowId should be used as well so that the process that owns the window group being joined has some means to identify the window. At any point following the creation of the QQnxWindow object, an application can change the window group it has joined. This is done by using the \e setWindowProperty function of the native interface to set the \e qnxWindowGroup property to the desired value, for example: \code QQuickView *view = new QQuickView(parent); view->create(); QGuiApplication::platformNativeInterface()->setWindowProperty(view->handle(), "qnxWindowGroup", group); \endcode To leave the current window group, one passes a null value for the property value, for example: \code QQuickView *view = new QQuickView(parent); view->create(); QGuiApplication::platformNativeInterface()->setWindowProperty(view->handle(), "qnxWindowGroup", QVariant()); \endcode \section1 Window Id The screen window id string property can be set on a window by assigning the desired value to a dynamic property \e qnxWindowId on the QWindow prior to the QQnxWindow having been created. This is often wanted when one joins a window group belonging to a different process. */ QQnxWindow::QQnxWindow(QWindow *window, screen_context_t context, bool needRootWindow) : QPlatformWindow(window), m_screenContext(context), m_window(0), m_screen(0), m_parentWindow(0), m_visible(false), m_exposed(true), m_windowState(Qt::WindowNoState), m_mmRendererWindow(0) { qWindowDebug() << Q_FUNC_INFO << "window =" << window << ", size =" << window->size(); QQnxScreen *platformScreen = static_cast<QQnxScreen *>(window->screen()->handle()); // If a qnxInitialWindowGroup property is set on the window we'll take this as an // indication that we want to create a child window and join that window group. const QVariant windowGroup = window->property("qnxInitialWindowGroup"); if (window->type() == Qt::CoverWindow) { // Cover windows have to be top level to be accessible to window delegate (i.e. navigator) // Desktop windows also need to be toplevel because they are not // supposed to be part of the window hierarchy tree m_isTopLevel = true; } else if (parent() || windowGroup.isValid()) { // If we have a parent we are a child window. Sometimes we have to be a child even if we // don't have a parent e.g. our parent might be in a different process. m_isTopLevel = false; } else { // We're parentless. If we're not using a root window, we'll always be a top-level window // otherwise only the first window is. m_isTopLevel = !needRootWindow || !platformScreen->rootWindow(); } if (window->type() == Qt::Desktop) // A desktop widget does not need a libscreen window return; if (m_isTopLevel) { 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 { Q_SCREEN_CHECKERROR( screen_create_window_type(&m_window, m_screenContext, SCREEN_CHILD_WINDOW), "Could not create child window"); } createWindowGroup(); // If the window has a qnxWindowId property, set this as the string id property. This generally // needs to be done prior to joining any group as it might be used by the owner of the // group to identify the window. const QVariant windowId = window->property("qnxWindowId"); if (windowId.isValid() && windowId.canConvert<QByteArray>()) { QByteArray id = windowId.toByteArray(); Q_SCREEN_CHECKERROR(screen_set_window_property_cv(m_window, SCREEN_PROPERTY_ID_STRING, id.size(), id), "Failed to set id"); } // If a window group has been provided join it now. If it's an empty string that's OK too, // it'll cause us not to join a group (the app will presumably join at some future time). if (windowGroup.isValid() && windowGroup.canConvert<QByteArray>()) joinWindowGroup(windowGroup.toByteArray()); }
void QQnxWindow::setBufferSize(const QSize &size) { qWindowDebug() << Q_FUNC_INFO << "window =" << window() << "size =" << size; // libscreen fails when creating empty buffers const QSize nonEmptySize = size.isEmpty() ? QSize(1, 1) : size; int format = pixelFormat(); if (nonEmptySize == m_bufferSize || format == -1) return; Q_SCREEN_CRITICALERROR( screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, &format), "Failed to set window format"); if (m_bufferSize.isValid()) { // destroy buffers first, if resized Q_SCREEN_CRITICALERROR(screen_destroy_window_buffers(m_window), "Failed to destroy window buffers"); } int val[2] = { nonEmptySize.width(), nonEmptySize.height() }; Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, val), "Failed to set window buffer size"); 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; 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.", MAX_BUFFER_COUNT, bufferCount); } // Set the transparency. According to QNX technical support, setting the window // transparency property should always be done *after* creating the window // buffers in order to guarantee the property is paid attention to. if (window()->requestedFormat().alphaBufferSize() == 0) { // To avoid overhead in the composition manager, disable blending // when the underlying window buffer doesn't have an alpha channel. val[0] = SCREEN_TRANSPARENCY_NONE; } else { // Normal alpha blending. This doesn't commit us to translucency; the // normal backfill during the painting will contain a fully opaque // alpha channel unless the user explicitly intervenes to make something // transparent. val[0] = SCREEN_TRANSPARENCY_SOURCE_OVER; } 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; resetBuffers(); }