Debian Codegraph @

src/plugins/platforms/eglfs/deviceintegration/eglfs_mali/qeglfsmaliintegration.cpp

raw
1 // Copyright (C) 2016 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
4 #include "qeglfsmaliintegration.h"
5
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <sys/ioctl.h>
9 #include <linux/fb.h>
10
11 #include <private/qcore_unix_p.h>
12
13 QT_BEGIN_NAMESPACE
14
15 struct shadow_fbdev_window {
16 unsigned short width;
17 unsigned short height;
18 };
19
20 void QEglFSMaliIntegration::platformInit()
21 {
22 // Keep the non-overridden base class functions based on fb0 working.
23 QEglFSDeviceIntegration::platformInit();
24
25 int fd = qt_safe_open("/dev/fb0", O_RDWR, 0);
26 if (fd == -1)
27 qWarning("Failed to open fb to detect screen resolution!");
28
29 struct fb_var_screeninfo vinfo;
30 memset(&vinfo, 0, sizeof(vinfo));
31 if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1)
32 qWarning("Could not get variable screen info");
33
34 vinfo.bits_per_pixel = 32;
35 vinfo.red.length = 8;
36 vinfo.green.length = 8;
37 vinfo.blue.length = 8;
38 vinfo.transp.length = 8;
39 vinfo.blue.offset = 0;
40 vinfo.green.offset = 8;
41 vinfo.red.offset = 16;
42 vinfo.transp.offset = 24;
43 #if 0
44 vinfo.yres_virtual = 2 * vinfo.yres;
45 #endif
46
47 if (ioctl(fd, FBIOPUT_VSCREENINFO, &vinfo) == -1)
48 qErrnoWarning(errno, "Unable to set double buffer mode!");
49
50 qt_safe_close(fd);
51 }
52
53 EGLNativeWindowType QEglFSMaliIntegration::createNativeWindow(QPlatformWindow *window, const QSize &size, const QSurfaceFormat &format)
54 {
55 Q_UNUSED(window);
56 Q_UNUSED(format);
57
58 shadow_fbdev_window *fbwin = reinterpret_cast<shadow_fbdev_window *>(malloc(sizeof(shadow_fbdev_window)));
59 if (NULL == fbwin)
60 return 0;
61
62 fbwin->width = size.width();
63 fbwin->height = size.height();
64 return (EGLNativeWindowType)fbwin;
65 }
66
67 void QEglFSMaliIntegration::destroyNativeWindow(EGLNativeWindowType window)
68 {
69 free((void*)window);
70 }
71
72 QT_END_NAMESPACE