5#include <QtFbSupport/private/qfbcursor_p.h>
6#include <QtFbSupport/private/qfbwindow_p.h>
8#include <QtCore/QRegularExpression>
9#include <QtGui/QPainter>
11#include <private/qcore_unix_p.h>
51 int depth = vinfo.bits_per_pixel;
53 depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length;
56 }
else if (
depth == 16) {
57 depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length;
66 int xoff = vinfo.xoffset;
67 int yoff = vinfo.yoffset;
72 if ((
uint)
w > vinfo.xres)
74 if ((
uint)
h > vinfo.yres)
77 int xxoff = userGeometry.
x(), yyoff = userGeometry.
y();
78 if (xxoff != 0 || yyoff != 0) {
79 if (xxoff < 0 || xxoff + w > (
int)(vinfo.xres))
80 xxoff = vinfo.xres -
w;
81 if (yyoff < 0 || yyoff + h > (
int)(vinfo.yres))
82 yyoff = vinfo.yres -
h;
86 xoff += (vinfo.xres -
w)/2;
87 yoff += (vinfo.yres -
h)/2;
94 if (
w == 0 ||
h == 0) {
95 qWarning(
"Unable to find screen geometry, using 320x240");
100 return QRect(xoff, yoff,
w,
h);
105 int mmWidth = mmSize.
width(), mmHeight = mmSize.
height();
107 if (mmWidth <= 0 && mmHeight <= 0) {
108 if (vinfo.width != 0 && vinfo.height != 0
109 && vinfo.width != UINT_MAX && vinfo.height != UINT_MAX) {
110 mmWidth = vinfo.width;
111 mmHeight = vinfo.height;
114 mmWidth =
qRound(
res.width() * 25.4 / dpi);
115 mmHeight =
qRound(
res.height() * 25.4 / dpi);
117 }
else if (mmWidth > 0 && mmHeight <= 0) {
118 mmHeight =
res.height() * mmWidth/
res.width();
119 }
else if (mmHeight > 0 && mmWidth <= 0) {
120 mmWidth =
res.width() * mmHeight/
res.height();
123 return QSize(mmWidth, mmHeight);
128 const fb_bitfield rgba[4] = {
info.red,
info.green,
135 const fb_bitfield argb8888[4] = {{16, 8, 0}, {8, 8, 0},
136 {0, 8, 0}, {24, 8, 0}};
137 const fb_bitfield abgr8888[4] = {{0, 8, 0}, {8, 8, 0},
138 {16, 8, 0}, {24, 8, 0}};
139 if (memcmp(rgba, argb8888, 4 *
sizeof(fb_bitfield)) == 0) {
141 }
else if (memcmp(rgba, argb8888, 3 *
sizeof(fb_bitfield)) == 0) {
143 }
else if (memcmp(rgba, abgr8888, 3 *
sizeof(fb_bitfield)) == 0) {
150 const fb_bitfield rgb888[4] = {{16, 8, 0}, {8, 8, 0},
151 {0, 8, 0}, {0, 0, 0}};
152 const fb_bitfield bgr888[4] = {{0, 8, 0}, {8, 8, 0},
153 {16, 8, 0}, {0, 0, 0}};
154 if (memcmp(rgba, rgb888, 3 *
sizeof(fb_bitfield)) == 0) {
156 }
else if (memcmp(rgba, bgr888, 3 *
sizeof(fb_bitfield)) == 0) {
163 const fb_bitfield rgb666[4] = {{12, 6, 0}, {6, 6, 0},
164 {0, 6, 0}, {0, 0, 0}};
165 if (memcmp(rgba, rgb666, 3 *
sizeof(fb_bitfield)) == 0)
170 const fb_bitfield rgb565[4] = {{11, 5, 0}, {5, 6, 0},
171 {0, 5, 0}, {0, 0, 0}};
172 const fb_bitfield bgr565[4] = {{0, 5, 0}, {5, 6, 0},
173 {11, 5, 0}, {0, 0, 0}};
174 if (memcmp(rgba, rgb565, 3 *
sizeof(fb_bitfield)) == 0) {
176 }
else if (memcmp(rgba, bgr565, 3 *
sizeof(fb_bitfield)) == 0) {
183 const fb_bitfield rgb1555[4] = {{10, 5, 0}, {5, 5, 0},
184 {0, 5, 0}, {15, 1, 0}};
185 const fb_bitfield bgr1555[4] = {{0, 5, 0}, {5, 5, 0},
186 {10, 5, 0}, {15, 1, 0}};
187 if (memcmp(rgba, rgb1555, 3 *
sizeof(fb_bitfield)) == 0) {
189 }
else if (memcmp(rgba, bgr1555, 3 *
sizeof(fb_bitfield)) == 0) {
196 const fb_bitfield rgb444[4] = {{8, 4, 0}, {4, 4, 0},
197 {0, 4, 0}, {0, 0, 0}};
198 if (memcmp(rgba, rgb444, 3 *
sizeof(fb_bitfield)) == 0)
216 const char *
const devs[] = {
"/dev/tty0",
"/dev/tty",
"/dev/console",
nullptr };
220 for (
const char *
const *dev = devs; *dev; ++dev) {
237 if (ioctl(ttyfd, KDGETMODE, oldMode) == 0) {
238 if (doSwitch && *oldMode != KD_GRAPHICS)
239 ioctl(ttyfd, KDSETMODE, KD_GRAPHICS);
245 ioctl(ttyfd, KDSETMODE, oldMode);
252 ioctl(
fd, FBIOBLANK, on ? VESA_POWERDOWN : VESA_NO_BLANKING);
256 : mArgs(
args), mFbFd(-1), mTtyFd(-1), mBlitter(
nullptr)
258 mMmap.data =
nullptr;
265 munmap(mMmap.data - mMmap.offset, mMmap.size);
286 bool doSwitchToGraphicsMode =
true;
289 for (
const QString &
arg : std::as_const(mArgs)) {
291 if (
arg ==
"nographicsmodeswitch"_L1)
292 doSwitchToGraphicsMode =
false;
293 else if (
arg.contains(mmSizeRx, &
match))
294 userMmSize =
QSize(
match.captured(1).toInt(),
match.captured(2).toInt());
295 else if (
arg.contains(sizeRx, &
match))
297 else if (
arg.contains(offsetRx, &
match))
299 else if (
arg.contains(ttyRx, &
match))
300 ttyDevice =
match.captured(1);
301 else if (
arg.contains(fbRx, &
match))
302 fbDevice =
match.captured(1);
306 fbDevice =
"/dev/fb0"_L1;
308 fbDevice =
"/dev/graphics/fb0"_L1;
310 qWarning(
"Unable to figure out framebuffer device. Specify it manually.");
323 fb_fix_screeninfo finfo;
324 fb_var_screeninfo vinfo;
325 memset(&vinfo, 0,
sizeof(vinfo));
326 memset(&finfo, 0,
sizeof(finfo));
328 if (ioctl(mFbFd, FBIOGET_FSCREENINFO, &finfo) != 0) {
333 if (ioctl(mFbFd, FBIOGET_VSCREENINFO, &vinfo)) {
339 mBytesPerLine = finfo.line_length;
346 mMmap.size = finfo.smem_len;
347 uchar *
data = (
unsigned char *)mmap(
nullptr, mMmap.size, PROT_READ | PROT_WRITE, MAP_SHARED, mFbFd, 0);
348 if ((
long)
data == -1) {
354 mMmap.data =
data + mMmap.offset;
379 mBlitter =
new QPainter(&mFbScreenImage);
417#include "moc_qlinuxfbscreen.cpp"
IOBluetoothDevice * device
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
QFbWindow * windowForId(WId wid) const
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
void initializeCompositor()
virtual QRegion doRedraw()
static QByteArray encodeName(const QString &fileName)
Converts fileName to an 8-bit encoding that you can use in native APIs.
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
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.
QLinuxFbScreen(const QStringList &args)
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.
bool initialize() override
QRegion doRedraw() override
The QPainter class performs low-level painting on widgets and other paint devices.
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
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...
QPixmap copy(int x, int y, int width, int height) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
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.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
constexpr QSize size() const noexcept
Returns the size of the rectangle.
constexpr void setTopLeft(const QPoint &p) noexcept
Set the top-left corner of the rectangle to the given position.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
The QRegion class specifies a clip region for a painter.
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void qErrnoWarning(const char *msg,...)
Combined button and popup list for selecting options.
static QRect determineGeometry(const struct fbtype &fb, const QRect &userGeometry)
static int openFramebufferDevice(const QString &dev)
static QSizeF determinePhysicalSize(const QSize &mmSize, const QSize &res)
int qRound(qfloat16 d) noexcept
static QImage::Format determineFormat(const FBInfo *fbinfo)
static QRect determineGeometry(const fb_var_screeninfo &vinfo, const QRect &userGeometry)
static int openTtyDevice(const QString &device)
static void resetTty(int ttyfd, int oldMode)
static void blankScreen(int fd, bool on)
static int determineDepth(const fb_var_screeninfo &vinfo)
static int openFramebufferDevice(const QString &dev)
static QSizeF determinePhysicalSize(const fb_var_screeninfo &vinfo, const QSize &mmSize, const QSize &res)
static void switchToGraphicsMode(int ttyfd, bool doSwitch, int *oldMode)
static QImage::Format determineFormat(const fb_var_screeninfo &info, int depth)
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
#define qPrintable(string)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
QFileInfo info(fileName)
[8]