1From 0eb7058b473069a04cde60a800dfd04148c0c8b1 Mon Sep 17 00:00:00 2001
2From: Yann E. MORIN <yann.morin.1998@free.fr>
3Date: Sat, 14 Dec 2020 21:15:17 +0100
4Subject: [PATCH] plugins/eglfs/gbm: don't FTBFS when EGLNativeDisplayType is not a pointer
5
6On some platforms, EGLNativeDisplayType is not a pointer, but some kind
7of integer, like an int (e.g. TI's SGX) or an unsigned int. In those
8cases, the build breaks with:
9
10    qeglfskmsgbmintegration.cpp: In member function ‘virtual void* QEglFSKmsGbmIntegration::createDisplay(EGLNativeDisplayType)’:
11    qeglfskmsgbmintegration.cpp:83:60: error: invalid conversion from ‘EGLNativeDisplayType’ {aka ‘int’} to ‘void*’ [-fpermissive]
12       83 |         display = getPlatformDisplay(EGL_PLATFORM_GBM_KHR, nativeDisplay, nullptr);
13          |                                                            ^~~~~~~~~~~~~
14          |                                                            |
15          |                                                            EGLNativeDisplayType {aka int}
16
17We fix that by casting nativeDisplay to void* as expected by
18getPlatformDisplay().
19
20We can do that, because usually, nativeDisplay is already a pointer, and
21thus this cast is a no-op. When it is not already a pointer, we either
22don't care because the code path will not be taken at runtime, or the
23integer really is an opaque handle to some internal, low-level memory
24management, much like a void* is an pointer to an opaque memory type...
25
26It is to be noted, though, that in some ABIs (like x32), the size of a
27nativeDisplay that is not already a pointer, might be bigger than that
28of a pointer. There is not much we can do here anyway, since there would
29be no way to fit that in a void* to begin with, and the build will still
30fail for those situations. Those types of ABIs are far frome being
31widespread, the most prominent one, x32, even being retired...
32
33To be noted further: a more usual solution (as suggested in QTBUG-72567
34or in Gerrit:248270) would be to first cast to a qintptr or a quintptr,
35before finally casting to a void*. However, casting to either (resp.)
36qintptr or quintptr first, risk the case that nativeDisplay is of the other
37kind of signedness, (resp.) unsigned or signed, which would also cause
38some compile-time breakage.
39
40Finally, if nativeDisplay is something that is not an int-like, and that
41can't be cast into a void*, this would be hugely weird, so much so, that
42we do not even attempt to catter for that case.
43
44Fixes: QTBUG-72567
45Inspired-by: https://codereview.qt-project.org/c/qt/qtbase/+/248270
46Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
47---
48
49diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp
50index d495a8d..059a580 100644
51--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp
52+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmintegration.cpp
53@@ -80,7 +80,9 @@
54     }
55
56     if (getPlatformDisplay) {
57-        display = getPlatformDisplay(EGL_PLATFORM_GBM_KHR, nativeDisplay, nullptr);
58+        // EGLNativeDisplayType may be int on some platforms but those
59+        // won't hit this path. Have to keep it compiling nonetheless.
60+        display = getPlatformDisplay(EGL_PLATFORM_GBM_KHR, reinterpret_cast<void *>(nativeDisplay), nullptr);
61     } else {
62         qCDebug(qLcEglfsKmsDebug, "No eglGetPlatformDisplay for GBM, falling back to eglGetDisplay");
63         display = eglGetDisplay(nativeDisplay);
64