13#include <QLoggingCategory>
14#include <QGuiApplication>
16#include <QtFbSupport/private/qfbcursor_p.h>
17#include <QtFbSupport/private/qfbwindow_p.h>
18#include <QtKmsSupport/private/qkmsdevice_p.h>
19#include <QtCore/private/qcore_unix_p.h>
49 const drmModeModeInfo &modeInfo(kmsOutput.
modes[kmsOutput.
mode]);
50 return QSize(modeInfo.hdisplay, modeInfo.vdisplay);
57 void close()
override;
59 void createFramebuffers();
60 void destroyFramebuffers();
69 void *nativeDisplay()
const override;
80 unsigned int tv_sec,
unsigned int tv_usec,
void *
user_data);
98 uint64_t hasDumbBuf = 0;
99 if (drmGetCap(
fd, DRM_CAP_DUMB_BUFFER, &hasDumbBuf) == -1 || !hasDumbBuf) {
100 qWarning(
"Dumb buffers not supported");
115 output.kmsOutput.cleanup(
this);
120 qCDebug(qLcFbDrm,
"Closing DRM device");
128 Q_UNREACHABLE_RETURN(
nullptr);
156 case DRM_FORMAT_BGR565:
167 case DRM_FORMAT_BGR565:
169 case DRM_FORMAT_XRGB8888:
170 case DRM_FORMAT_XBGR8888:
172 case DRM_FORMAT_XRGB2101010:
173 case DRM_FORMAT_XBGR2101010:
183 case DRM_FORMAT_XRGB8888:
184 case DRM_FORMAT_XBGR8888:
186 case DRM_FORMAT_ARGB8888:
190 case DRM_FORMAT_BGR565:
192 case DRM_FORMAT_XRGB2101010:
193 case DRM_FORMAT_XBGR2101010:
195 case DRM_FORMAT_ARGB2101010:
196 case DRM_FORMAT_ABGR2101010:
206 const uint32_t
w =
size.width();
207 const uint32_t
h =
size.height();
209 drm_mode_create_dumb creq = {
215 if (drmIoctl(
fd(), DRM_IOCTL_MODE_CREATE_DUMB, &creq) == -1) {
220 Framebuffer &fb(
output->fb[bufferIdx]);
221 fb.handle = creq.handle;
222 fb.pitch = creq.pitch;
224 qCDebug(qLcFbDrm,
"Got a dumb buffer for size %dx%d and bpp %u: handle %u, pitch %u, size %u",
225 w,
h, bpp, fb.handle, fb.pitch, (
uint) fb.size);
227 uint32_t handles[4] = { fb.handle };
228 uint32_t
strides[4] = { fb.pitch };
231 if (drmModeAddFB2(
fd(),
w,
h,
output->kmsOutput.drm_format,
237 drm_mode_map_dumb mreq = {
241 if (drmIoctl(
fd(), DRM_IOCTL_MODE_MAP_DUMB, &mreq) == -1) {
245 fb.p = mmap(
nullptr, fb.size, PROT_READ | PROT_WRITE, MAP_SHARED,
fd(), mreq.offset);
251 qCDebug(qLcFbDrm,
"FB is %u (DRM format 0x%x), mapped at %p", fb.fb,
output->kmsOutput.drm_format, fb.p);
252 memset(fb.p, 0, fb.size);
263 if (!createFramebuffer(&
output,
i))
273 Framebuffer &fb(
output->fb[bufferIdx]);
275 munmap(fb.p, fb.size);
277 if (drmModeRmFB(
fd(), fb.fb) == -1)
281 drm_mode_destroy_dumb dreq = { fb.handle };
282 if (drmIoctl(
fd(), DRM_IOCTL_MODE_DESTROY_DUMB, &dreq) == -1)
283 qErrnoWarning(errno,
"Failed to destroy dumb buffer %u", fb.handle);
292 destroyFramebuffer(&
output,
i);
299 drmModeModeInfo &modeInfo(
output.kmsOutput.modes[
output.kmsOutput.mode]);
300 if (drmModeSetCrtc(
fd(),
output.kmsOutput.crtc_id,
output.fb[0].fb, 0, 0,
301 &
output.kmsOutput.connector_id, 1, &modeInfo) == -1) {
306 output.kmsOutput.mode_set =
true;
311void QLinuxFbDevice::pageFlipHandler(
int fd,
unsigned int sequence,
312 unsigned int tv_sec,
unsigned int tv_usec,
327 if (drmModePageFlip(
fd(),
output->kmsOutput.crtc_id, fb.
fb, DRM_MODE_PAGE_FLIP_EVENT,
output) == -1) {
332 const int fbIdx =
output->backFb;
333 while (
output->backFb == fbIdx) {
334 drmEventContext drmEvent;
335 memset(&drmEvent, 0,
sizeof(drmEvent));
336 drmEvent.version = 2;
337 drmEvent.vblank_handler =
nullptr;
338 drmEvent.page_flip_handler = pageFlipHandler;
341 drmHandleEvent(
fd(), &drmEvent);
359 delete m_screenConfig;
367 if (!m_device->
open())
434#include "moc_qlinuxfbdrmscreen.cpp"
void initializeCompositor()
virtual QRegion doRedraw()
Format
The following image formats are available in Qt.
@ Format_A2RGB30_Premultiplied
QString devicePath() const
virtual void loadConfig()
QPlatformScreen * createScreen(const QKmsOutput &output) override
QLinuxFbDevice(QKmsScreenConfig *screenConfig)
void * nativeDisplay() const override
void destroyFramebuffers()
void createFramebuffers()
void swapBuffers(Output *output)
void registerScreen(QPlatformScreen *screen, bool isPrimary, const QPoint &virtualPos, const QList< QPlatformScreen * > &virtualSiblings) override
bool initialize() override
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
QLinuxFbDrmScreen(const QStringList &args)
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...
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
The QRegion class specifies a clip region for a painter.
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
void qErrnoWarning(const char *msg,...)
Combined button and popup list for selecting options.
static int qt_safe_open(const char *pathname, int flags, mode_t mode=0777)
static int qt_safe_close(int fd)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void * user_data
static QT_BEGIN_NAMESPACE void pageFlipHandler(int fd, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void *user_data)
#define DRM_FORMAT_RGB565
#define DRM_FORMAT_ABGR8888
static uint32_t bppForDrmFormat(uint32_t drmFormat)
static QImage::Format formatForDrmFormat(uint32_t drmFormat)
static int depthForDrmFormat(uint32_t drmFormat)
static QT_BEGIN_NAMESPACE const int BUFFER_COUNT
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLfloat GLfloat GLfloat GLfloat h
GLuint GLsizei const GLuint const GLintptr * offsets
GLsizei const GLuint const GLintptr const GLsizei * strides
#define qPrintable(string)
static char * toLocal8Bit(char *out, QStringView in, QStringConverter::State *state)
#define QStringLiteral(str)
QT_BEGIN_NAMESPACE typedef uchar * output
file open(QIODevice::ReadOnly)
QList< drmModeModeInfo > modes