16QEglFSKmsEglDeviceScreen::QEglFSKmsEglDeviceScreen(QEglFSKmsDevice *device,
const QKmsOutput &output)
17 : QEglFSKmsScreen(device, output)
18 , m_default_fb_handle(uint32_t(-1))
19 , m_default_fb_id(uint32_t(-1))
21 const int fd = device->fd();
23 struct drm_mode_create_dumb createRequest;
24 createRequest.width = output.size.width();
25 createRequest.height = output.size.height();
26 createRequest.bpp = 32;
27 createRequest.flags = 0;
29 qCDebug(qLcEglfsKmsDebug,
"Creating dumb fb %dx%d", createRequest.width, createRequest.height);
31 int ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &createRequest);
33 qFatal(
"Unable to create dumb buffer.\n");
35 m_default_fb_handle = createRequest.handle;
37 uint32_t handles[4] = { 0, 0, 0, 0 };
38 uint32_t pitches[4] = { 0, 0, 0, 0 };
39 uint32_t offsets[4] = { 0, 0, 0, 0 };
41 handles[0] = createRequest.handle;
42 pitches[0] = createRequest.pitch;
45 ret = drmModeAddFB2(fd, createRequest.width, createRequest.height, DRM_FORMAT_ARGB8888, handles,
46 pitches, offsets, &m_default_fb_id, 0);
48 qFatal(
"Unable to add fb\n");
50 qCDebug(qLcEglfsKmsDebug,
"Added dumb fb %dx%d handle:%u pitch:%d id:%u", createRequest.width, createRequest.height,
51 createRequest.handle, createRequest.pitch, m_default_fb_id);
57 const int fd = device()->fd();
59 if (m_default_fb_id != uint32_t(-1)) {
60 ret = drmModeRmFB(fd, m_default_fb_id);
62 qErrnoWarning(
"drmModeRmFB failed");
65 if (m_default_fb_handle != uint32_t(-1)) {
66 struct drm_mode_destroy_dumb destroyRequest;
67 destroyRequest.handle = m_default_fb_handle;
69 ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroyRequest);
71 qErrnoWarning(
"DRM_IOCTL_MODE_DESTROY_DUMB failed");
74 const int remainingScreenCount = qGuiApp->screens().size();
75 qCDebug(qLcEglfsKmsDebug,
"Screen dtor. %p Remaining screens: %d",
this, remainingScreenCount);
76 if (!remainingScreenCount && !device()->screenConfig()->separateScreens())
94 QKmsOutput &op(output());
95 const int fd = device()->fd();
96 const uint32_t w = op.modes[op.mode].hdisplay;
97 const uint32_t h = op.modes[op.mode].vdisplay;
102 drmModeCrtcPtr currentMode = drmModeGetCrtc(fd, op.crtc_id);
103 const bool alreadySet = currentMode && currentMode->width == w && currentMode->height == h;
105 drmModeFreeCrtc(currentMode);
111 static bool envVarSet =
false;
112 static bool alwaysDoSet = qEnvironmentVariableIntValue(
"QT_QPA_EGLFS_ALWAYS_SET_MODE", &envVarSet);
113 if (envVarSet && !alwaysDoSet) {
114 qCDebug(qLcEglfsKmsDebug,
"Mode already set");
119 qCDebug(qLcEglfsKmsDebug,
"Setting mode");
120 int ret = drmModeSetCrtc(fd, op.crtc_id,
121 m_default_fb_id, 0, 0,
125 qErrnoWarning(errno,
"drmModeSetCrtc failed");
128 if (!op.forced_plane_set) {
129 op.forced_plane_set =
true;
131 if (op.wants_forced_plane) {
132 qCDebug(qLcEglfsKmsDebug,
"Setting plane %u", op.forced_plane_id);
133 int ret = drmModeSetPlane(fd, op.forced_plane_id, op.crtc_id, m_default_fb_id, 0,
135 0 << 16, 0 << 16, op.size.width() << 16, op.size.height() << 16);
137 qErrnoWarning(errno,
"drmModeSetPlane failed");