23 QImage::Format format = QImage::Format_Invalid;
25 switch (fbinfo->BitsPerPixel) {
27 if (fbinfo->Alpha.Bits)
28 format = QImage::Format_ARGB32;
30 format = QImage::Format_RGB32;
33 format = QImage::Format_RGB888;
36 format = QImage::Format_RGB666;
39 format = QImage::Format_RGB16;
42 format = QImage::Format_RGB555;
45 format = QImage::Format_RGB444;
50 format = QImage::Format_Mono;
79 QRegularExpression fbRx(
"fb=(.*)"_L1);
80 QRegularExpression sizeRx(
"size=(\\d+)x(\\d+)"_L1);
81 QRegularExpression offsetRx(
"offset=(\\d+)x(\\d+)"_L1);
87 foreach (
const QString &arg, mArgs) {
88 QRegularExpressionMatch match;
89 if (arg.contains(sizeRx, &match))
90 userGeometry.setSize(QSize(match.captured(1).toInt(), match.captured(2).toInt()));
91 else if (arg.contains(offsetRx, &match))
92 userGeometry.setTopLeft(QPoint(match.captured(1).toInt(), match.captured(2).toInt()));
93 else if (arg.contains(fbRx, &match))
94 fbDevice = match.captured(1);
97 if (fbDevice.isEmpty()) {
99 err = gh_FB_get_driver_by_name(NULL, &mFbd);
100 if (err != Success) {
101 uintptr_t context = 0;
103 err = gh_FB_get_next_driver(&context, &mFbd);
106 err = gh_FB_get_driver_by_name(qPrintable(fbDevice), &mFbd);
108 if (err != Success) {
109 qErrnoWarning(
"Failed to open framebuffer %s: %d", qPrintable(fbDevice), err);
113 memset(&mFbinfo, 0,
sizeof(FBInfo));
114 CheckSuccess(gh_FB_check_info(mFbd, &mFbinfo));
115 if (userGeometry.width() && userGeometry.height()) {
116 mFbinfo.Width = userGeometry.width();
117 mFbinfo.Height = userGeometry.height();
118 err = gh_FB_check_info(mFbd, &mFbinfo);
119 if (err != Success) {
120 qErrnoWarning(
"Unsupported resolution %dx%d for %s: %d",
121 userGeometry.width(), userGeometry.height(),
122 qPrintable(fbDevice), err);
127 if (mFbinfo.MMapSize) {
128 err = AllocateAnyMemoryRegionWithCookie(__ghs_VirtualMemoryRegionPool,
129 mFbinfo.MMapSize, &mVMR, &mVMRCookie);
130 if (err != Success) {
131 qErrnoWarning(
"Could not mmap: %d", err);
135 err = gh_FB_open_mmap(mFbd, &mFbinfo, mVMR, &mFbh);
137 err = gh_FB_open(mFbd, &mFbinfo, &mFbh);
139 if (err != Success) {
140 qErrnoWarning(
"Could not open framebuffer: %d", err);
144 CheckSuccess(gh_FB_get_info(mFbh, &mFbinfo));
146 mDepth = mFbinfo.BitsPerPixel;
147 mGeometry = QRect(0, 0, mFbinfo.Width, mFbinfo.Height);
148 mFormat = determineFormat(&mFbinfo);
151 int mmWidth = qRound((mFbinfo.Width * 25.4) / dpi);
152 int mmHeight = qRound((mFbinfo.Height * 25.4) / dpi);
153 mPhysicalSize = QSizeF(mmWidth, mmHeight);
155 QFbScreen::initializeCompositor();
156 mFbScreenImage = QImage((uchar *)mFbinfo.Start, mFbinfo.Width, mFbinfo.Height,
157 mFbinfo.BytesPerLine, mFormat);
159 mCursor =
new QFbCursor(
this);
193 width = mFbScreenImage.width() - x;
195 height = mFbScreenImage.height() - y;
196 return QPixmap::fromImage(mFbScreenImage).copy(x, y, width, height);
199 QFbWindow *window = windowForId(wid);
201 const QRect geom = window->geometry();
203 width = geom.width() - x;
205 height = geom.height() - y;
206 QRect rect(geom.topLeft() + QPoint(x, y), QSize(width, height));
207 rect &= window->geometry();
208 return QPixmap::fromImage(mFbScreenImage).copy(rect);