linuxfb屏幕旋转90度
-
前言
事情是这样的,在开发板上使用Qt来做一些界面开发,但是我们是用的屏幕是800*1280的屏幕,也就是横向打点,就是说宽比长要大,做界面的话不太好看,所以在不改变驱动和设备树的情况下,在应用层实现屏幕旋转也能满足我们的需求。
由于开发板上面没有显卡,像openGL、EGLFS这种来实现屏幕旋转也不现实,所以最终还是只能使用Linuxfb。但是Qt5的Linuxfb不支持旋转,所以需要拿到QT Linuxfb的源码自己添加一些参数就能实现了。
网上找了一下,只找到了一个5.4的patch,直接用用不了,所以就要只能自己来改源码,
这里用的是buildroot来构建Qt系统的,下面介绍如何获取并修改源码,如果不想修改的可以直接复制补丁文件,生成patch,打patch。一、源码获取
在buildroot构建系统中,有一个dl目录,存放的都是各种源码,其中QT的源码就放在里面。
我们将源码拷贝一份,创建git仓库,使用git进行打补丁。修改后,生成pach,将pach打入源码中即可。二、修改源码
<font color=#999AAA >代码如下:
diff --git a/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp b/src/plugins/platforms/linuxfb/qlinuxfbscreen .cpp index cb8962d4..9c89a4a3 100644 --- a/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp +++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp @@ -287,7 +287,7 @@ static void blankScreen(int fd, bool on) } QLinuxFbScreen::QLinuxFbScreen(const QStringList &args) - : mArgs(args), mFbFd(-1), mTtyFd(-1), mBlitter(0) + : mArgs(args), mFbFd(-1), mTtyFd(-1), mBlitter(0), mRotation(90) { mMmap.data = 0; } @@ -310,9 +310,10 @@ bool QLinuxFbScreen::initialize() { QRegularExpression ttyRx(QLatin1String("tty=(.*)")); QRegularExpression fbRx(QLatin1String("fb=(.*)")); - QRegularExpression mmSizeRx(QLatin1String("mmsize=(\\d+)x(\\d+)")); + 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; @@ -334,6 +335,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()) { @@ -372,9 +375,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; @@ -384,11 +395,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); mCursor = new QFbCursor(this); @@ -413,8 +424,27 @@ QRegion QLinuxFbScreen::doRedraw() mBlitter = new QPainter(&mFbScreenImage); mBlitter->setCompositionMode(QPainter::CompositionMode_Source); - for (const QRect &rect : touched) - mBlitter->drawImage(rect, mScreenImage, rect); + 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/plugins/platforms/linuxfb/qlinuxfbscreen.h b/src/plugins/platforms/linuxfb/qlinuxfbscreen.h index c7ce455e..f7076bf1 100644 --- a/src/plugins/platforms/linuxfb/qlinuxfbscreen.h +++ b/src/plugins/platforms/linuxfb/qlinuxfbscreen.h @@ -64,6 +64,7 @@ private: QStringList mArgs; int mFbFd; int mTtyFd; + int mRotation; QImage mFbScreenImage; int mBytesPerLine;
源码修改完成后,初始化git仓库,打补丁。
git init git add . git commit -m "test" git format-patch HEAD^
三、将补丁拷贝到指定目录
buildroot构建系统,它会自动将补丁打上,所以我们只需要将上面生成的补丁放到指定目录下即可。
目录如下:neza-d1-buildroot/package/qt5/qt5base
下图即是我们添加的补丁。
四、编译
make
编译完成即可完成屏幕旋转了
五、添加环境变量
由于屏幕旋转过去了,但是触摸屏还没旋转,所以我们需要添加QT环境变量配置触摸屏,这里用的是TSLIB进行触摸屏校准的。
在/etc/profile文件最后添加下面内容,其中TSLIB_TSDEVICE后面的event根据自己屏幕event设备进行填写。export TSLIB_CONSOLEDEVICE=none export TSLIB_FBDEVICE=/dev/fb0 export TSLIB_TSDEVICE=/dev/input/event5 export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0 export QT_QPA_GENERIC_PLUGINS=tslib:$TSLIB_TSDEVICE
重启系统即可。
-
-
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号