概述
qt4在嵌入式板子上运行时,只要在参数后面加-display "Transformed:Rot90"就可以旋转90度,qt5 opengl有这个功能,但是linuxfb没有这个功能。
qt5.4的linuxfb旋转显示补丁代码如下: 取自https://borkedlabs.com/misc/qt5.4_linuxfb_rotation.patch_.zip 可能需要翻墙,所以直接贴代码,另外这个补丁有个缺陷,触摸点会对应不上。
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;
打完后,使用方法如下:加参数-platform linuxfb:fb=/dev/fb0:rotation=90
最后
以上就是结实大树为你收集整理的qt5 linuxfb下屏幕旋转补丁的全部内容,希望文章能够帮你解决qt5 linuxfb下屏幕旋转补丁所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复