int gf_setup(gf_setup_t *setup, int argc, char * const argv[], unsigned flags) { gf_dev_t gdev; unsigned dispno = 0; const char *dev_name = NULL; int layer_idx = GF_SETUP_LAYER_MAIN, rc, verbose = 0; gf_sid_t sid = GF_SID_INVALID; unsigned vx1 = 0, vx2 = ~0, vy1 = 0, vy2 = ~0; memset(setup, 0, sizeof *setup); setup->fname = strdup("tt0419m_.ttf"); #ifdef _MSC_VER #else opterr = 0; while ((rc = getopt(argc, argv, "d:D:l:s:vx:y:f:")) != -1) { switch (rc) { case 'd': if (isdigit(*optarg)) { dev_name = GF_DEVICE_INDEX(atoi(optarg)); } else { dev_name = optarg; } break; case 'D': dispno = atoi(optarg); break; case 'l': layer_idx = atoi(optarg); break; case 's': sid = (gf_sid_t)atoi(optarg); break; case 'v': verbose = ~0; break; case 'x': switch (*optarg++) { case '1': vx1 = atoi(optarg); break; case '2': vx2 = atoi(optarg); break; default: break; } break; case 'y': switch (*optarg++) { case '1': vy1 = atoi(optarg); break; case '2': vy2 = atoi(optarg); break; default: break; } break; case 'f': setup->fname = strdup(optarg); break; default: break; } } #endif if ((rc = gf_dev_attach(&gdev, dev_name, NULL)) == GF_ERR_OK) { if (sid != GF_SID_INVALID) { gf_surface_t surface; if ((rc = gf_surface_attach_by_sid(&surface, gdev, sid)) == GF_ERR_OK) { gf_context_t context; if ((rc = gf_context_create(&context)) == GF_ERR_OK) { if ((rc = gf_context_set_surface(context, surface)) == GF_ERR_OK) { gf_surface_info_t sinfo; gf_surface_get_info(surface, &sinfo); --sinfo.w; --sinfo.h; if (vx2 > sinfo.w) { vx2 = sinfo.w; } if (vy2 > sinfo.h) { vy2 = sinfo.h; } if (vx1 <= vx2 && vy1 <= vy2 && (vx1 || vy1 || vx2 < sinfo.w || vy2 < sinfo.h)) { gf_context_set_clipping(context, vx1, vy1, vx2, vy2); setup->x1 = vx1; setup->x2 = vx2; setup->y1 = vy1; setup->y2 = vy2; } setup->surface1 = surface; setup->context = context; setup->gdev = gdev; return GF_ERR_OK; } gf_context_free(context); } gf_surface_free(surface); } } else { gf_display_t display; gf_display_info_t dinfo; if ((rc = gf_display_attach(&display, gdev, dispno, &dinfo)) == GF_ERR_OK) { gf_layer_t layer; if (verbose) { fprintf(stderr, "Display %d:\n\tResolution: %dX%d\n", dispno, dinfo.xres, dinfo.yres); fprintf(stderr, "\tRefresh rate: %d\n\tPixel format: ", dinfo.refresh); switch (dinfo.format) { case GF_FORMAT_PAL8: fprintf(stderr, "PAL8"); break; case GF_FORMAT_PACK_ARGB1555: fprintf(stderr, "ARGB1555"); break; case GF_FORMAT_PACK_RGB565: fprintf(stderr, "RGB565"); break; case GF_FORMAT_BGR888: fprintf(stderr, "BGR888"); break; case GF_FORMAT_BGRA8888: fprintf(stderr, "BGRA8888"); break; default: fprintf(stderr, "%x", (unsigned)dinfo.format); break; } fprintf(stderr, "\n\tNumber of layers: %d\n", dinfo.nlayers); fprintf(stderr, "\tMain layer index: %d\n", dinfo.main_layer_index); } if ((rc = gf_layer_attach(&layer, display, layer_idx == GF_SETUP_LAYER_MAIN ? dinfo.main_layer_index : layer_idx, 0)) == GF_ERR_OK) { gf_surface_t surface1, surface2 = NULL; int layer_format; layer_format = find_rgb_format(layer); if(verbose && layer_format != dinfo.format) { fprintf(stderr, "\tChoosing non-default layer format: "); switch (layer_format) { case GF_FORMAT_PAL8: fprintf(stderr, "PAL8"); break; case GF_FORMAT_PACK_ARGB1555: fprintf(stderr, "ARGB1555"); break; case GF_FORMAT_PACK_RGB565: fprintf(stderr, "RGB565"); break; case GF_FORMAT_BGR888: fprintf(stderr, "BGR888"); break; case GF_FORMAT_BGRA8888: fprintf(stderr, "BGRA8888"); break; default: fprintf(stderr, "%x", (unsigned)layer_format); break; } fprintf(stderr, "\n"); } dinfo.format = layer_format; if ((rc = gf_surface_create_layer(&surface1, &layer, 1, 0, dinfo.xres, dinfo.yres, dinfo.format, NULL, 0)) == GF_ERR_OK && (!(flags & GF_SETUP_FLAG_DBLBUFFER) || (rc = gf_surface_create_layer(&surface2, &layer, 1, 0, dinfo.xres, dinfo.yres, dinfo.format, NULL, 0)) == GF_ERR_OK)) { if (verbose) { gf_surface_info_t sinfo; gf_surface_get_info(surface1, &sinfo); fprintf(stderr, "Surface:\n\tSID = %d\n", (unsigned)sinfo.sid); fprintf(stderr, "\tFlags = %x\n", sinfo.flags); } gf_layer_set_surfaces(layer, &surface1, 1); if ((rc = gf_layer_update(layer, 0)) == GF_ERR_OK) { gf_context_t context = NULL; if ((flags & GF_SETUP_FLAG_NOCONTEXT) || ((rc = gf_context_create(&context)) == GF_ERR_OK && (rc = gf_context_set_surface(context, surface1)) == GF_ERR_OK)) { setup->gdev = gdev; setup->display = display; memcpy(&setup->display_info, &dinfo, sizeof dinfo); setup->layer = layer; setup->surface1 = surface1; setup->surface2 = surface2; setup->context = context; return GF_ERR_OK; } if (context != NULL) { gf_context_free(context); } } } } } } gf_dev_detach(gdev); } return rc; }
/*! \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; }
/*! \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; }
/* * Function : Framebuffer Driver Initializer * */ byte QNXGF_init(LIBAROMA_FBP me) { /* Allocating Internal Data */ ALOGV("QNXGF Initialized Internal Data"); QNXGF_INTERNALP mi = (QNXGF_INTERNALP) calloc(sizeof(QNXGF_INTERNAL),1); if (!mi) { ALOGE("QNXGF malloc internal data - Memory Error"); return 0; } libaroma_mutex_init(___qnxfbmutex); /* Set Internal Address */ me->internal = (voidp) mi; me->release = &QNXGF_release; me->double_buffer = 0; // 1; /************************* Init of Init QNX GF ******************************/ /* Device Attach */ if (gf_dev_attach( &mi->gdev, GF_DEVICE_INDEX(0), &mi->gdev_info ) != GF_ERR_OK) { ALOGE("QNXGF gf_dev_attach failed"); goto error; } /* Display Attach */ if (gf_display_attach( &mi->display, mi->gdev, 0, &mi->display_info ) != GF_ERR_OK) { ALOGE("QNXGF gf_display_attach failed"); gf_dev_detach(mi->gdev); goto error; } /* Layer Attach */ if (gf_layer_attach( &mi->layer, mi->display, 0, 0 ) != GF_ERR_OK) { ALOGE("QNXGF gf_layer_attach failed"); gf_display_detach(mi->display); gf_dev_detach(mi->gdev); goto error; } /* Create Surface */ if (gf_surface_create_layer( &mi->surface, &mi->layer, 1, 0, mi->display_info.xres, mi->display_info.yres, GF_FORMAT_PKLE_RGB565, NULL, 0 ) != GF_ERR_OK) { ALOGE("QNXGF gf_surface_create_layer failed"); gf_layer_detach(mi->layer); gf_display_detach(mi->display); gf_dev_detach(mi->gdev); goto error; } /* Set Surface */ gf_layer_set_surfaces(mi->layer, &mi->surface, 1); /* Create Context */ if (gf_context_create(&mi->context) != GF_ERR_OK) { ALOGE("QNXGF gf_context_create failed"); gf_surface_free(mi->surface); gf_layer_detach(mi->layer); gf_display_detach(mi->display); gf_dev_detach(mi->gdev); goto error; } /* Context Set Layer */ if (gf_context_set_surface(mi->context, mi->surface) != GF_ERR_OK) { ALOGE("QNXGF gf_context_set_surface failed"); gf_context_free(mi->context); gf_surface_free(mi->surface); gf_layer_detach(mi->layer); gf_display_detach(mi->display); gf_dev_detach(mi->gdev); goto error; } /* if (gf_display_set_dpms(mi->display,GF_DPMS_ON) != GF_ERR_OK) { ALOGI("QNXGF gf_display_set_dpms failed"); } else{ ALOGI("QNXGF gf_display_set_dpms OK"); } */ /************************* End of Init QNX GF *******************************/ /* Set AROMA Core Framebuffer Instance Values */ me->w = mi->display_info.xres; /* Width */ me->h = mi->display_info.yres; /* Height */ me->sz = me->w * me->h; /* Width x Height */ /* Set Callbacks */ me->start_post = &QNXGF_start_post; me->post = &QNXGF_post; me->end_post = &QNXGF_end_post; me->snapshoot = NULL; /* DUMP INFO */ QNXGF_dump(mi); /* Fixed DPI */ me->dpi = 160; /* OK */ goto ok; /* Return */ error: free(mi); return 0; ok: return 1; }