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