15QEglFSKmsEglDeviceScreen::QEglFSKmsEglDeviceScreen(QEglFSKmsDevice *device,
const QKmsOutput &output)
16 : QEglFSKmsScreen(device, output)
17 , m_default_fb_handle(uint32_t(-1))
18 , m_default_fb_id(uint32_t(-1))
20 const int fd = device->fd();
22 struct drm_mode_create_dumb createRequest;
23 createRequest.width = output.size.width();
24 createRequest.height = output.size.height();
25 createRequest.bpp = 32;
26 createRequest.flags = 0;
28 qCDebug(qLcEglfsKmsDebug,
"Creating dumb fb %dx%d", createRequest.width, createRequest.height);
30 int ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &createRequest);
32 qFatal(
"Unable to create dumb buffer.\n");
34 m_default_fb_handle = createRequest.handle;
36 uint32_t handles[4] = { 0, 0, 0, 0 };
37 uint32_t pitches[4] = { 0, 0, 0, 0 };
38 uint32_t offsets[4] = { 0, 0, 0, 0 };
40 handles[0] = createRequest.handle;
41 pitches[0] = createRequest.pitch;
44 ret = drmModeAddFB2(fd, createRequest.width, createRequest.height, DRM_FORMAT_ARGB8888, handles,
45 pitches, offsets, &m_default_fb_id, 0);
47 qFatal(
"Unable to add fb\n");
49 qCDebug(qLcEglfsKmsDebug,
"Added dumb fb %dx%d handle:%u pitch:%d id:%u", createRequest.width, createRequest.height,
50 createRequest.handle, createRequest.pitch, m_default_fb_id);
56 const int fd = device()->fd();
58 if (m_default_fb_id != uint32_t(-1)) {
59 ret = drmModeRmFB(fd, m_default_fb_id);
61 qErrnoWarning(
"drmModeRmFB failed");
64 if (m_default_fb_handle != uint32_t(-1)) {
65 struct drm_mode_destroy_dumb destroyRequest;
66 destroyRequest.handle = m_default_fb_handle;
68 ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroyRequest);
70 qErrnoWarning(
"DRM_IOCTL_MODE_DESTROY_DUMB failed");
73 const int remainingScreenCount = qGuiApp->screens().size();
74 qCDebug(qLcEglfsKmsDebug,
"Screen dtor. %p Remaining screens: %d",
this, remainingScreenCount);
75 if (!remainingScreenCount && !device()->screenConfig()->separateScreens())
93 QKmsOutput &op(output());
94 const int fd = device()->fd();
95 const uint32_t w = op.modes[op.mode].hdisplay;
96 const uint32_t h = op.modes[op.mode].vdisplay;
101 drmModeCrtcPtr currentMode = drmModeGetCrtc(fd, op.crtc_id);
102 const bool alreadySet = currentMode && currentMode->width == w && currentMode->height == h;
104 drmModeFreeCrtc(currentMode);
110 static bool envVarSet =
false;
111 static bool alwaysDoSet = qEnvironmentVariableIntValue(
"QT_QPA_EGLFS_ALWAYS_SET_MODE", &envVarSet);
112 if (envVarSet && !alwaysDoSet) {
113 qCDebug(qLcEglfsKmsDebug,
"Mode already set");
118 qCDebug(qLcEglfsKmsDebug,
"Setting mode");
119 int ret = drmModeSetCrtc(fd, op.crtc_id,
120 m_default_fb_id, 0, 0,
124 qErrnoWarning(errno,
"drmModeSetCrtc failed");
127 if (!op.forced_plane_set) {
128 op.forced_plane_set =
true;
130 if (op.wants_forced_plane) {
131 qCDebug(qLcEglfsKmsDebug,
"Setting plane %u", op.forced_plane_id);
132 int ret = drmModeSetPlane(fd, op.forced_plane_id, op.crtc_id, m_default_fb_id, 0,
134 0 << 16, 0 << 16, op.size.width() << 16, op.size.height() << 16);
136 qErrnoWarning(errno,
"drmModeSetPlane failed");