1*4882a593SmuzhiyunFrom a710cf924929a1a102b3d07938bd217303e41e93 Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Jeffy Chen <jeffy.chen@rock-chips.com> 3*4882a593SmuzhiyunDate: Mon, 28 Feb 2022 11:31:12 +0800 4*4882a593SmuzhiyunSubject: [PATCH 28/28] linuxfbdrm: Support setting screen size and display 5*4882a593Smuzhiyun rectangle 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunUsage: 8*4882a593Smuzhiyunexport QT_QPA_PLATFORM=linuxfb:size=480x200:rect=0,20,480,220 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunSigned-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 11*4882a593Smuzhiyun--- 12*4882a593Smuzhiyun .../platforms/linuxfb/qlinuxfbdrmscreen.cpp | 30 +++++++++++++++++-- 13*4882a593Smuzhiyun .../platforms/linuxfb/qlinuxfbdrmscreen.h | 2 ++ 14*4882a593Smuzhiyun 2 files changed, 30 insertions(+), 2 deletions(-) 15*4882a593Smuzhiyun 16*4882a593Smuzhiyundiff --git a/src/plugins/platforms/linuxfb/qlinuxfbdrmscreen.cpp b/src/plugins/platforms/linuxfb/qlinuxfbdrmscreen.cpp 17*4882a593Smuzhiyunindex b6e3960d..04df126e 100644 18*4882a593Smuzhiyun--- a/src/plugins/platforms/linuxfb/qlinuxfbdrmscreen.cpp 19*4882a593Smuzhiyun+++ b/src/plugins/platforms/linuxfb/qlinuxfbdrmscreen.cpp 20*4882a593Smuzhiyun@@ -416,14 +416,27 @@ void QLinuxFbDevice::swapBuffers(Output *output) 21*4882a593Smuzhiyun QLinuxFbDrmScreen::QLinuxFbDrmScreen(const QStringList &args) 22*4882a593Smuzhiyun : m_screenConfig(nullptr), 23*4882a593Smuzhiyun m_device(nullptr), 24*4882a593Smuzhiyun- m_rotation(0) 25*4882a593Smuzhiyun+ m_rotation(0), 26*4882a593Smuzhiyun+ m_screenSize(), 27*4882a593Smuzhiyun+ m_displayRect() 28*4882a593Smuzhiyun { 29*4882a593Smuzhiyun QRegularExpression rotationRx(QLatin1String("rotation=(0|90|180|270)")); 30*4882a593Smuzhiyun+ QRegularExpression sizeRx(QLatin1String("size=([1-9]\\d*)x([1-9]\\d*)")); 31*4882a593Smuzhiyun+ QRegularExpression rectRx(QLatin1String("rect=(\\d+),(\\d+),(\\d+),(\\d+)")); 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun for (const QString &arg : qAsConst(args)) { 34*4882a593Smuzhiyun QRegularExpressionMatch match; 35*4882a593Smuzhiyun if (arg.contains(rotationRx, &match)) 36*4882a593Smuzhiyun m_rotation = match.captured(1).toInt(); 37*4882a593Smuzhiyun+ 38*4882a593Smuzhiyun+ if (arg.contains(sizeRx, &match)) 39*4882a593Smuzhiyun+ m_screenSize = 40*4882a593Smuzhiyun+ QSize(match.captured(1).toInt(), match.captured(2).toInt()); 41*4882a593Smuzhiyun+ 42*4882a593Smuzhiyun+ if (arg.contains(rectRx, &match)) 43*4882a593Smuzhiyun+ m_displayRect = 44*4882a593Smuzhiyun+ QRect(match.captured(1).toInt(), match.captured(2).toInt(), 45*4882a593Smuzhiyun+ match.captured(3).toInt(), match.captured(4).toInt()); 46*4882a593Smuzhiyun } 47*4882a593Smuzhiyun } 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun@@ -451,7 +464,14 @@ bool QLinuxFbDrmScreen::initialize() 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun QLinuxFbDevice::Output *output(m_device->output(0)); 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun- mGeometry = QRect(QPoint(0, 0), output->currentRes()); 54*4882a593Smuzhiyun+ if (m_screenSize.isEmpty()) 55*4882a593Smuzhiyun+ m_screenSize = output->currentRes(); 56*4882a593Smuzhiyun+ 57*4882a593Smuzhiyun+ mGeometry = QRect(QPoint(0, 0), m_screenSize); 58*4882a593Smuzhiyun+ 59*4882a593Smuzhiyun+ if (m_displayRect.isEmpty()) 60*4882a593Smuzhiyun+ m_displayRect = mGeometry; 61*4882a593Smuzhiyun+ 62*4882a593Smuzhiyun if(m_rotation % 180) { 63*4882a593Smuzhiyun int tmp = mGeometry.width(); 64*4882a593Smuzhiyun mGeometry.setWidth(mGeometry.height()); 65*4882a593Smuzhiyun@@ -472,6 +492,9 @@ bool QLinuxFbDrmScreen::initialize() 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun QRegion QLinuxFbDrmScreen::doRedraw() 68*4882a593Smuzhiyun { 69*4882a593Smuzhiyun+ qreal scaleX = qreal(m_displayRect.width()) / m_screenSize.width(); 70*4882a593Smuzhiyun+ qreal scaleY = qreal(m_displayRect.height()) / m_screenSize.height(); 71*4882a593Smuzhiyun+ 72*4882a593Smuzhiyun const QRegion dirty = QFbScreen::doRedraw(); 73*4882a593Smuzhiyun if (dirty.isEmpty()) 74*4882a593Smuzhiyun return dirty; 75*4882a593Smuzhiyun@@ -498,6 +521,9 @@ QRegion QLinuxFbDrmScreen::doRedraw() 76*4882a593Smuzhiyun // Do not waste time with the default SourceOver. 77*4882a593Smuzhiyun pntr.setCompositionMode(QPainter::CompositionMode_Source); 78*4882a593Smuzhiyun for (const QRect &rect : qAsConst(output->dirty[output->backFb])) { 79*4882a593Smuzhiyun+ pntr.translate(m_displayRect.x(), m_displayRect.y()); 80*4882a593Smuzhiyun+ pntr.scale(scaleX, scaleY); 81*4882a593Smuzhiyun+ 82*4882a593Smuzhiyun if(m_rotation) { 83*4882a593Smuzhiyun if(m_rotation == 180) 84*4882a593Smuzhiyun pntr.translate(mGeometry.width()/2, mGeometry.height()/2); 85*4882a593Smuzhiyundiff --git a/src/plugins/platforms/linuxfb/qlinuxfbdrmscreen.h b/src/plugins/platforms/linuxfb/qlinuxfbdrmscreen.h 86*4882a593Smuzhiyunindex 4065392d..679d851b 100644 87*4882a593Smuzhiyun--- a/src/plugins/platforms/linuxfb/qlinuxfbdrmscreen.h 88*4882a593Smuzhiyun+++ b/src/plugins/platforms/linuxfb/qlinuxfbdrmscreen.h 89*4882a593Smuzhiyun@@ -63,6 +63,8 @@ private: 90*4882a593Smuzhiyun QLinuxFbDevice *m_device; 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun int m_rotation; 93*4882a593Smuzhiyun+ QSize m_screenSize; 94*4882a593Smuzhiyun+ QRect m_displayRect; 95*4882a593Smuzhiyun }; 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun QT_END_NAMESPACE 98*4882a593Smuzhiyun-- 99*4882a593Smuzhiyun2.20.1 100*4882a593Smuzhiyun 101