예제 #1
0
/*! \reimp
  Connects to QNX's io-display based device based on the \a displaySpec parameters
  from the \c{QWS_DISPLAY} environment variable. See the QQnxScreen class documentation
  for possible parameters.

  \sa QQnxScreen
 */
bool QQnxScreen::connect(const QString &displaySpec)
{
    const QStringList params = displaySpec.split(QLatin1Char(':'), QString::SkipEmptyParts);

    bool isOk = false;
    QRegExp deviceRegExp(QLatin1String("^device=(.+)$"));
    if (params.indexOf(deviceRegExp) != -1) {
        isOk = attachDevice(d, deviceRegExp.cap(1).toLocal8Bit().constData());
    } else {
        // no device specified - attach to device 0 (the default)
        isOk = attachDevice(d, GF_DEVICE_INDEX(0));
    }

    if (!isOk)
        return false;

    qDebug("QQnxScreen: Attached to Device, number of displays: %d", d->deviceInfo.ndisplays);

    // default to display 0
    int displayIndex = 0;
    QRegExp displayRegexp(QLatin1String("^display=(\\d+)$"));
    if (params.indexOf(displayRegexp) != -1) {
        displayIndex = displayRegexp.cap(1).toInt();
    }

    if (!attachDisplay(d, displayIndex))
        return false;

    qDebug("QQnxScreen: Attached to Display %d, resolution %dx%d, refresh %d Hz",
            displayIndex, d->displayInfo.xres, d->displayInfo.yres,
            d->displayInfo.refresh);


    // default to main_layer_index from the displayInfo struct
    int layerIndex = 0;
    QRegExp layerRegexp(QLatin1String("^layer=(\\d+)$"));
    if (params.indexOf(layerRegexp) != -1) {
        layerIndex = layerRegexp.cap(1).toInt();
    } else {
        layerIndex = d->displayInfo.main_layer_index;
    }

    if (!attachLayer(d, layerIndex))
        return false;

    // tell QWSDisplay the width and height of the display
    w = dw = d->displayInfo.xres;
    h = dh = d->displayInfo.yres;

    // we only support 32 bit displays for now.
    QScreen::d = 32;

    // assume 72 dpi as default, to calculate the physical dimensions if not specified
    const int defaultDpi = 72;

    // Handle display physical size spec.
    QRegExp mmWidthRegexp(QLatin1String("^mmWidth=(\\d+)$"));
    if (params.indexOf(mmWidthRegexp) == -1) {
        physWidth = qRound(dw * 25.4 / defaultDpi);
    } else {
        physWidth = mmWidthRegexp.cap(1).toInt();
    }

    QRegExp mmHeightRegexp(QLatin1String("^mmHeight=(\\d+)$"));
    if (params.indexOf(mmHeightRegexp) == -1) {
        physHeight = qRound(dh * 25.4 / defaultDpi);
    } else {
        physHeight = mmHeightRegexp.cap(1).toInt();
    }

    // create a hardware surface with our dimensions. In the old days, it was possible
    // to get a pointer directly to the hw surface, so we could blit directly. Now, we
    // have to use one indirection more, because it's not guaranteed that the hw surface
    // is mappable into our process.
    if (!createHwSurface(d, w, h))
        return false;

    // create an in-memory linear surface that is used by QWS. QWS will blit directly in here.
    if (!createMemSurface(d, w, h))
        return false;

    // set the address of the in-memory buffer that QWS is blitting to
    data = d->memSurfaceInfo.vaddr;
    // set the line stepping
    lstep = d->memSurfaceInfo.stride;

    // the overall size of the in-memory buffer is linestep * height
    size = mapsize = lstep * h;

    // create a QNX drawing context
    if (!createContext(d))
        return false;

    // we're always using a software cursor for now. Initialize it here.
    QScreenCursor::initSoftwareCursor();

    // done, the driver should be connected to the display now.
    return true;
}
예제 #2
0
파일: qscreenqnx_qws.cpp 프로젝트: BGmot/Qt
/*!
    \reimp
    Connects to QNX's io-display based device based on the \a displaySpec parameters
    from the \c{QWS_DISPLAY} environment variable. See the QQnxScreen class documentation
    for possible parameters.

    \sa QQnxScreen
*/
bool QQnxScreen::connect(const QString &displaySpec)
{
    const QStringList params = displaySpec.split(QLatin1Char(':'), QString::SkipEmptyParts);

    // default to device 0
    int deviceIndex = 0;
    if (!params.isEmpty()) {
        QRegExp deviceRegExp(QLatin1String("^device=(.+)$"));
        if (params.indexOf(deviceRegExp) != -1)
            deviceIndex = deviceRegExp.cap(1).toInt();
    }

    if (!attachDevice(d, GF_DEVICE_INDEX(deviceIndex)))
        return false;

    qDebug("QQnxScreen: Attached to Device, number of displays: %d", d->deviceInfo.ndisplays);

    // default to display id passed to constructor
    int displayIndex = displayId;
    if (!params.isEmpty()) {
        QRegExp displayRegexp(QLatin1String("^display=(\\d+)$"));
        if (params.indexOf(displayRegexp) != -1)
            displayIndex = displayRegexp.cap(1).toInt();
    }

    if (!attachDisplay(d, displayIndex))
        return false;

    qDebug("QQnxScreen: Attached to Display %d, resolution %dx%d, refresh %d Hz",
            displayIndex, d->displayInfo.xres, d->displayInfo.yres, d->displayInfo.refresh);

    // default to main_layer_index from the displayInfo struct
    int layerIndex = d->displayInfo.main_layer_index;
    if (!params.isEmpty()) {
        QRegExp layerRegexp(QLatin1String("^layer=(\\d+)$"));
        if (params.indexOf(layerRegexp) != -1)
            layerIndex = layerRegexp.cap(1).toInt();
    }

    if (!attachLayer(d, layerIndex))
        return false;

    // determine the pixel format and the pixel type
    switch (d->displayInfo.format) {
#if defined(QT_QWS_DEPTH_32) || defined(QT_QWS_DEPTH_GENERIC)
        case GF_FORMAT_ARGB8888:
            pixeltype = QScreen::BGRPixel;
        // fall through
        case GF_FORMAT_BGRA8888:
            setPixelFormat(QImage::Format_ARGB32);
            break;
#endif
#if defined(QT_QWS_DEPTH_24)
        case GF_FORMAT_BGR888:
            pixeltype = QScreen::BGRPixel;
            setPixelFormat(QImage::Format_RGB888);
            break;
#endif
#if defined(QT_QWS_DEPTH_16) || defined(QT_QWS_DEPTH_GENERIC)
        case GF_FORMAT_PACK_RGB565:
        case GF_FORMAT_PKLE_RGB565:
        case GF_FORMAT_PKBE_RGB565:
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
            setFrameBufferLittleEndian((d->displayInfo.format & GF_FORMAT_PKLE) == GF_FORMAT_PKLE);
#endif
            setPixelFormat(QImage::Format_RGB16);
            break;
#endif
        default:
            return false;
    }

    // tell QWSDisplay the width and height of the display
    w = dw = d->displayInfo.xres;
    h = dh = d->displayInfo.yres;
    QScreen::d = (d->displayInfo.format & GF_FORMAT_BPP);  // colour depth

    // assume 72 dpi as default, to calculate the physical dimensions if not specified
    const int defaultDpi = 72;
    // Handle display physical size
    physWidth = qRound(dw * 25.4 / defaultDpi);
    physHeight = qRound(dh * 25.4 / defaultDpi);
    if (!params.isEmpty()) {
        QRegExp mmWidthRegexp(QLatin1String("^mmWidth=(\\d+)$"));
        if (params.indexOf(mmWidthRegexp) != -1)
            physWidth = mmWidthRegexp.cap(1).toInt();

        QRegExp mmHeightRegexp(QLatin1String("^mmHeight=(\\d+)$"));
        if (params.indexOf(mmHeightRegexp) != -1)
            physHeight = mmHeightRegexp.cap(1).toInt();
    }

    if (QApplication::type() == QApplication::GuiServer) {
        // create a hardware surface with our dimensions. In the old days, it was possible
        // to get a pointer directly to the hw surface, so we could blit directly. Now, we
        // have to use one indirection more, because it's not guaranteed that the hw surface
        // is mappable into our process.
        if (!createHwSurface(d, w, h))
            return false;
    }

    // create an in-memory linear surface that is used by QWS. QWS will blit directly in here.
    if (!createMemSurface(d, w, h))
        return false;

    // set the address of the in-memory buffer that QWS is blitting to
    data = d->memSurfaceInfo.vaddr;
    // set the line stepping
    lstep = d->memSurfaceInfo.stride;

    // the overall size of the in-memory buffer is linestep * height
    size = mapsize = lstep * h;

    // done, the driver should be connected to the display now.
    return true;
}