Screen rotation patch under qt5 linuxfb

qt4 when running on an embedded board, just add -display after the parameter "Transformed: Rot90" can be rotated 90 degrees, qt5 opengl have this feature, but linuxfb not have this feature.

The rotating display qt5.4 linuxfb patch code is as follows: from https://borkedlabs.com/misc/qt5.4_linuxfb_rotation.patch_.zip    may take over the wall, so the code directly attached, this additional patch has a flaw, the touch point will do not correspond.

diff --git a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.cpp b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp
index a66c9fa..a5b5f13 100644
--- a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.cpp
+++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp
@@ -290,7 +290,7 @@ static void blankScreen(int fd, bool on)
 }
 
 QLinuxFbScreen::QLinuxFbScreen(const QStringList &args)
-    : mArgs(args), mFbFd(-1), mBlitter(0)
+    : mArgs(args), mFbFd(-1), mBlitter(0), mRotation(90)
 {
 }
 
@@ -316,6 +316,7 @@ bool QLinuxFbScreen::initialize()
     QRegularExpression mmSizeRx(QLatin1String("mmsize=(\\d+)x(\\d+)"));
     QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)"));
     QRegularExpression offsetRx(QLatin1String("offset=(\\d+)x(\\d+)"));
+    QRegularExpression rotationRx(QLatin1String("rotation=(0|90|180|270)"));
 
     QString fbDevice, ttyDevice;
     QSize userMmSize;
@@ -337,6 +338,8 @@ bool QLinuxFbScreen::initialize()
             ttyDevice = match.captured(1);
         else if (arg.contains(fbRx, &match))
             fbDevice = match.captured(1);
+        else if (arg.contains(rotationRx, &match))
+            mRotation = match.captured(1).toInt();
     }
 
     if (fbDevice.isEmpty()) {
@@ -375,9 +378,17 @@ bool QLinuxFbScreen::initialize()
     mDepth = determineDepth(vinfo);
     mBytesPerLine = finfo.line_length;
     QRect geometry = determineGeometry(vinfo, userGeometry);
+    QRect originalGeometry = geometry;
+    if( mRotation == 90 || mRotation == 270 )
+    {
+        int tmp = geometry.width();
+        geometry.setWidth(geometry.height());
+        geometry.setHeight(tmp);
+    }
+
     mGeometry = QRect(QPoint(0, 0), geometry.size());
     mFormat = determineFormat(vinfo, mDepth);
-    mPhysicalSize = determinePhysicalSize(vinfo, userMmSize, geometry.size());
+    mPhysicalSize = determinePhysicalSize(vinfo, userMmSize, originalGeometry.size());
 
     // mmap the framebuffer
     mMmap.size = finfo.smem_len;
@@ -387,11 +398,11 @@ bool QLinuxFbScreen::initialize()
         return false;
     }
 
-    mMmap.offset = geometry.y() * mBytesPerLine + geometry.x() * mDepth / 8;
+    mMmap.offset = originalGeometry.y() * mBytesPerLine + originalGeometry.x() * mDepth / 8;
     mMmap.data = data + mMmap.offset;
 
     QFbScreen::initializeCompositor();
-    mFbScreenImage = QImage(mMmap.data, geometry.width(), geometry.height(), mBytesPerLine, mFormat);
+    mFbScreenImage = QImage(mMmap.data, originalGeometry.width(), originalGeometry.height(), mBytesPerLine, mFormat);
 
     QByteArray hideCursorVal = qgetenv("QT_QPA_FB_HIDECURSOR");
 #if !defined(Q_OS_ANDROID) || defined(Q_OS_ANDROID_NO_SDK)
@@ -436,7 +447,26 @@ QRegion QLinuxFbScreen::doRedraw()
 
     QVector<QRect> rects = touched.rects();
     for (int i = 0; i < rects.size(); i++)
+    {
+        if( mRotation == 90 || mRotation == 270 )
+        {
+            mBlitter->translate(mGeometry.height()/2, mGeometry.width()/2);
+        }
+        else if( mRotation == 180 )
+        {
+            mBlitter->translate(mGeometry.width()/2, mGeometry.height()/2);
+        }
+
+        if( mRotation != 0 )
+        {
+            mBlitter->rotate(mRotation);
+            mBlitter->translate(-mGeometry.width()/2, -mGeometry.height()/2);
+        }
+
         mBlitter->drawImage(rects[i], *mScreenImage, rects[i]);
+
+        mBlitter->resetTransform();
+    }
     return touched;
 }
 
diff --git a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.h b/src/plugins/platforms/linuxfb/qlinuxfbscreen.h
index 1997d46..a34414f 100644
--- a/src.orig/plugins/platforms/linuxfb/qlinuxfbscreen.h
+++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.h
@@ -57,6 +57,7 @@ private:
     QStringList mArgs;
     int mFbFd;
     int mTtyFd;
+    int mRotation;
 
     QImage mFbScreenImage;
     int mBytesPerLine;

After playing, using the following method: add parameters -platform linuxfb: fb = / dev / fb0: rotation = 90

Guess you like

Origin blog.csdn.net/zmlovelx/article/details/83782966