Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qintegrityfbscreen.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QtFbSupport/private/qfbcursor_p.h>
6#include <QtFbSupport/private/qfbwindow_p.h>
7#include <QtCore/QRegularExpression>
8#include <QtGui/QPainter>
9
10#include <qimage.h>
11#include <qdebug.h>
12
13#include <INTEGRITY.h>
14#include <memory_region.h>
15
17
18using namespace Qt::StringLiterals;
19
20static QImage::Format determineFormat(const FBInfo *fbinfo)
21{
23
24 switch (fbinfo->BitsPerPixel) {
25 case 32:
26 if (fbinfo->Alpha.Bits)
28 else
30 break;
31 case 24:
33 break;
34 case 18:
36 break;
37 case 16:
39 break;
40 case 15:
42 break;
43 case 12:
45 break;
46 case 8:
47 break;
48 case 1:
49 format = QImage::Format_Mono; //###: LSB???
50 break;
51 default:
52 break;
53 }
54
55 return format;
56}
57
59 : mArgs(args), mBlitter(0)
60{
61}
62
64{
65 if (mFbh) {
66 MemoryRegion vmr;
67 CheckSuccess(gh_FB_close_munmap(mFbh, &vmr));
68 CheckSuccess(DeallocateMemoryRegionWithCookie(__ghs_VirtualMemoryRegionPool,
69 vmr, mVMRCookie));
70 }
71
72 delete mBlitter;
73}
74
76{
77 Error err;
78 QRegularExpression fbRx("fb=(.*)"_L1);
79 QRegularExpression sizeRx("size=(\\d+)x(\\d+)"_L1);
80 QRegularExpression offsetRx("offset=(\\d+)x(\\d+)"_L1);
81
82 QString fbDevice;
83 QRect userGeometry;
84
85 // Parse arguments
86 foreach (const QString &arg, mArgs) {
88 if (arg.contains(sizeRx, &match))
89 userGeometry.setSize(QSize(match.captured(1).toInt(), match.captured(2).toInt()));
90 else if (arg.contains(offsetRx, &match))
91 userGeometry.setTopLeft(QPoint(match.captured(1).toInt(), match.captured(2).toInt()));
92 else if (arg.contains(fbRx, &match))
93 fbDevice = match.captured(1);
94 }
95
96 if (fbDevice.isEmpty()) {
97 /* no driver specified, try to get default one */
98 err = gh_FB_get_driver_by_name(NULL, &mFbd);
99 if (err != Success) {
100 uintptr_t context = 0;
101 /* no default driver, take the first available one */
102 err = gh_FB_get_next_driver(&context, &mFbd);
103 }
104 } else {
105 err = gh_FB_get_driver_by_name(qPrintable(fbDevice), &mFbd);
106 }
107 if (err != Success) {
108 qErrnoWarning("Failed to open framebuffer %s: %d", qPrintable(fbDevice), err);
109 return false;
110 }
111
112 memset(&mFbinfo, 0, sizeof(FBInfo));
113 CheckSuccess(gh_FB_check_info(mFbd, &mFbinfo));
114 if (userGeometry.width() && userGeometry.height()) {
115 mFbinfo.Width = userGeometry.width();
116 mFbinfo.Height = userGeometry.height();
117 err = gh_FB_check_info(mFbd, &mFbinfo);
118 if (err != Success) {
119 qErrnoWarning("Unsupported resolution %dx%d for %s: %d",
120 userGeometry.width(), userGeometry.height(),
121 qPrintable(fbDevice), err);
122 return false;
123 }
124 }
125
126 if (mFbinfo.MMapSize) {
127 err = AllocateAnyMemoryRegionWithCookie(__ghs_VirtualMemoryRegionPool,
128 mFbinfo.MMapSize, &mVMR, &mVMRCookie);
129 if (err != Success) {
130 qErrnoWarning("Could not mmap: %d", err);
131 return false;
132 }
133
134 err = gh_FB_open_mmap(mFbd, &mFbinfo, mVMR, &mFbh);
135 } else {
136 err = gh_FB_open(mFbd, &mFbinfo, &mFbh);
137 }
138 if (err != Success) {
139 qErrnoWarning("Could not open framebuffer: %d", err);
140 return false;
141 }
142
143 CheckSuccess(gh_FB_get_info(mFbh, &mFbinfo));
144
145 mDepth = mFbinfo.BitsPerPixel;
146 mGeometry = QRect(0, 0, mFbinfo.Width, mFbinfo.Height);
147 mFormat = determineFormat(&mFbinfo);
148
149 const int dpi = 100;
150 int mmWidth = qRound((mFbinfo.Width * 25.4) / dpi);
151 int mmHeight = qRound((mFbinfo.Height * 25.4) / dpi);
152 mPhysicalSize = QSizeF(mmWidth, mmHeight);
153
155 mFbScreenImage = QImage((uchar *)mFbinfo.Start, mFbinfo.Width, mFbinfo.Height,
156 mFbinfo.BytesPerLine, mFormat);
157
158 mCursor = new QFbCursor(this);
159
160 return true;
161}
162
164{
165 QRegion touched = QFbScreen::doRedraw();
166
167 if (touched.isEmpty())
168 return touched;
169
170 if (!mBlitter)
171 mBlitter = new QPainter(&mFbScreenImage);
172
173 for (QRect rect : touched) {
174 FBRect fbrect = {
175 (uint32_t)rect.left(),
176 (uint32_t)rect.top(),
177 (uint32_t)rect.width(),
178 (uint32_t)rect.height()
179 };
180 mBlitter->drawImage(rect, mScreenImage, rect);
181 gh_FB_expose(mFbh, &fbrect, NULL);
182 }
183 return touched;
184}
185
186// grabWindow() grabs "from the screen" not from the backingstores.
187// In integrityfb's case it will also include the mouse cursor.
188QPixmap QIntegrityFbScreen::grabWindow(WId wid, int x, int y, int width, int height) const
189{
190 if (!wid) {
191 if (width < 0)
192 width = mFbScreenImage.width() - x;
193 if (height < 0)
194 height = mFbScreenImage.height() - y;
195 return QPixmap::fromImage(mFbScreenImage).copy(x, y, width, height);
196 }
197
199 if (window) {
200 const QRect geom = window->geometry();
201 if (width < 0)
202 width = geom.width() - x;
203 if (height < 0)
204 height = geom.height() - y;
205 QRect rect(geom.topLeft() + QPoint(x, y), QSize(width, height));
206 rect &= window->geometry();
207 return QPixmap::fromImage(mFbScreenImage).copy(rect);
208 }
209
210 return QPixmap();
211}
212
214
QImage mScreenImage
Definition qfbscreen_p.h:89
QFbWindow * windowForId(WId wid) const
void initializeCompositor()
Definition qfbscreen.cpp:32
virtual QRegion doRedraw()
QFbCursor * mCursor
Definition qfbscreen_p.h:84
QRect mGeometry
Definition qfbscreen_p.h:85
QImage::Format mFormat
Definition qfbscreen_p.h:87
QSizeF mPhysicalSize
Definition qfbscreen_p.h:88
\inmodule QtGui
Definition qimage.h:37
int width() const
Returns the width of the image.
int height() const
Returns the height of the image.
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_RGB888
Definition qimage.h:55
@ Format_RGB32
Definition qimage.h:46
@ Format_Invalid
Definition qimage.h:42
@ Format_RGB666
Definition qimage.h:51
@ Format_RGB444
Definition qimage.h:56
@ Format_RGB555
Definition qimage.h:53
@ Format_Mono
Definition qimage.h:43
@ Format_RGB16
Definition qimage.h:49
@ Format_ARGB32
Definition qimage.h:47
QPixmap grabWindow(WId wid, int x, int y, int width, int height) const override
This function is called when Qt needs to be able to grab the content of a window.
QRegion doRedraw() override
QIntegrityFbScreen(const QStringList &args)
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition qpixmap.cpp:1437
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
\inmodule QtCore
Definition qsize.h:208
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
rect
[4]
void qErrnoWarning(const char *msg,...)
Combined button and popup list for selecting options.
static void * context
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
static QImage::Format determineFormat(const FBInfo *fbinfo)
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLint GLsizei width
GLint GLsizei GLsizei GLenum format
GLint y
SSL_CTX int void * arg
#define qPrintable(string)
Definition qstring.h:1531
@ Success
Definition main.cpp:3325
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
unsigned char uchar
Definition qtypes.h:32
aWidget window() -> setWindowTitle("New Window Title")
[2]
QJSValueList args