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 QQnxWindow::setGeometryHelper(const QRect &rect) { qWindowDebug() << Q_FUNC_INFO << "window =" << window() << ", (" << rect.x() << "," << rect.y() << "," << rect.width() << "," << rect.height() << ")"; // Call base class method QPlatformWindow::setGeometry(rect); // Set window geometry equal to widget geometry int val[2]; val[0] = rect.x(); val[1] = rect.y(); Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, val), "Failed to set window position"); val[0] = rect.width(); val[1] = rect.height(); Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val), "Failed to set window size"); // Set viewport size equal to window size Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val), "Failed to set window source size"); screen_flush_context(m_screenContext, 0); QWindowSystemInterface::handleGeometryChange(window(), rect); }
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); }
void QQnxRasterWindow::blitPreviousToCurrent(const QRegion ®ion, int dx, int dy, bool flush) { qRasterWindowDebug() << Q_FUNC_INFO << "window =" << window(); // Abort if previous buffer is invalid or if nothing to copy if (m_previousBufferIndex == -1 || region.isEmpty()) return; QQnxBuffer ¤tBuffer = m_buffers[m_currentBufferIndex]; QQnxBuffer &previousBuffer = m_buffers[m_previousBufferIndex]; // Break down region into non-overlapping rectangles const QVector<QRect> rects = region.rects(); for (int i = rects.size() - 1; i >= 0; i--) { // Clip rectangle to bounds of target const QRect rect = rects[i].intersected(currentBuffer.rect()); if (rect.isEmpty()) continue; // Setup blit operation int attribs[] = { SCREEN_BLIT_SOURCE_X, rect.x(), SCREEN_BLIT_SOURCE_Y, rect.y(), SCREEN_BLIT_SOURCE_WIDTH, rect.width(), SCREEN_BLIT_SOURCE_HEIGHT, rect.height(), SCREEN_BLIT_DESTINATION_X, rect.x() + dx, SCREEN_BLIT_DESTINATION_Y, rect.y() + dy, SCREEN_BLIT_DESTINATION_WIDTH, rect.width(), SCREEN_BLIT_DESTINATION_HEIGHT, rect.height(), SCREEN_BLIT_END }; // Queue blit operation Q_SCREEN_CHECKERROR(screen_blit(m_screenContext, currentBuffer.nativeBuffer(), previousBuffer.nativeBuffer(), attribs), "Failed to blit buffers"); } // Check if flush requested if (flush) { // Wait for all blits to complete Q_SCREEN_CHECKERROR(screen_flush_blits(m_screenContext, SCREEN_WAIT_IDLE), "Failed to flush blits"); // Buffer was modified outside the CPU currentBuffer.invalidateInCache(); } }
void QQnxRasterWindow::post(const QRegion &dirty) { // How double-buffering works // -------------------------- // // The are two buffers, the previous one and the current one. // The previous buffer always contains the complete, full image of the whole window when it // was last posted. // The current buffer starts with the complete, full image of the second to last posting // of the window. // // During painting, Qt paints on the current buffer. Thus, when Qt has finished painting, the // current buffer contains the second to last image plus the newly painted regions. // Since the second to last image is too old, we copy over the image from the previous buffer, but // only for those regions that Qt didn't paint (because that would overwrite what Qt has just // painted). This is the copyPreviousToCurrent() call below. // // After the call to copyPreviousToCurrent(), the current buffer contains the complete, full image of the // whole window in its current state, and we call screen_post_window() to make the new buffer // available to libscreen (called "posting"). There, only the regions that Qt painted on are // posted, as nothing else has changed. // // After that, the previous and the current buffers are swapped, and the whole cycle starts anew. // Check if render buffer exists and something was rendered if (m_currentBufferIndex != -1 && !dirty.isEmpty()) { qRasterWindowDebug() << Q_FUNC_INFO << "window =" << window(); QQnxBuffer ¤tBuffer = m_buffers[m_currentBufferIndex]; // Copy unmodified region from old render buffer to new render buffer; // required to allow partial updates QRegion preserve = m_previousDirty - dirty - m_scrolled; blitPreviousToCurrent(preserve, 0, 0); // Calculate region that changed QRegion modified = preserve + dirty + m_scrolled; QRect rect = modified.boundingRect(); int dirtyRect[4] = { rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height() }; // Update the display with contents of render buffer Q_SCREEN_CHECKERROR( screen_post_window(nativeHandle(), currentBuffer.nativeBuffer(), 1, dirtyRect, 0), "Failed to post window"); // Advance to next nender buffer m_previousBufferIndex = m_currentBufferIndex++; if (m_currentBufferIndex >= MAX_BUFFER_COUNT) m_currentBufferIndex = 0; // Save modified region and clear scrolled region m_previousDirty = dirty; m_scrolled = QRegion(); windowPosted(); } }
void QQnxWindow::setOpacity(qreal level) { qWindowDebug() << Q_FUNC_INFO << "window =" << window() << "opacity =" << level; // Set window global alpha int val = (int)(level * 255); Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_GLOBAL_ALPHA, &val), "Failed to set global alpha"); screen_flush_context(m_screenContext, 0); }
void QQnxWindow::updateVisibility(bool parentVisible) { qWindowDebug() << Q_FUNC_INFO << "parentVisible =" << parentVisible << "window =" << window(); // Set window visibility int val = (m_visible && parentVisible) ? 1 : 0; Q_SCREEN_CHECKERROR(screen_set_window_property_iv(m_window, SCREEN_PROPERTY_VISIBLE, &val), "Failed to set window visibility"); Q_FOREACH (QQnxWindow *childWindow, m_childWindows) childWindow->updateVisibility(m_visible && parentVisible); }
QT_BEGIN_NAMESPACE static QSize determineScreenSize(screen_display_t display, bool primaryScreen) { int val[2]; const int result = screen_get_display_property_iv(display, SCREEN_PROPERTY_PHYSICAL_SIZE, val); Q_SCREEN_CHECKERROR(result, "Failed to query display physical size"); if (result != 0) { return QSize(150, 90); } if (val[0] > 0 && val[1] > 0) return QSize(val[0], val[1]); qScreenDebug("QQnxScreen: screen_get_display_property_iv() reported an invalid " "physical screen size (%dx%d). Falling back to QQNX_PHYSICAL_SCREEN_SIZE " "environment variable.", val[0], val[1]); const QString envPhySizeStr = qgetenv("QQNX_PHYSICAL_SCREEN_SIZE"); if (!envPhySizeStr.isEmpty()) { const QStringList envPhySizeStrList = envPhySizeStr.split(QLatin1Char(',')); const int envWidth = envPhySizeStrList.size() == 2 ? envPhySizeStrList[0].toInt() : -1; const int envHeight = envPhySizeStrList.size() == 2 ? envPhySizeStrList[1].toInt() : -1; if (envWidth <= 0 || envHeight <= 0) { qFatal("QQnxScreen: The value of QQNX_PHYSICAL_SCREEN_SIZE must be in the format " "\"width,height\" in mm, with width, height > 0. " "Example: QQNX_PHYSICAL_SCREEN_SIZE=150,90"); return QSize(150, 90); } return QSize(envWidth, envHeight); } #if defined(QQNX_PHYSICAL_SCREEN_SIZE_DEFINED) const QSize defSize(QQNX_PHYSICAL_SCREEN_WIDTH, QQNX_PHYSICAL_SCREEN_HEIGHT); qWarning("QQnxScreen: QQNX_PHYSICAL_SCREEN_SIZE variable not set. Falling back to defines " "QQNX_PHYSICAL_SCREEN_WIDTH/QQNX_PHYSICAL_SCREEN_HEIGHT (%dx%d)", defSize.width(), defSize.height()); return defSize; #else if (primaryScreen) qFatal("QQnxScreen: QQNX_PHYSICAL_SCREEN_SIZE variable not set. " "Could not determine physical screen size."); return QSize(150, 90); #endif }
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 }
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(); }