7#include <QtGui/private/qeglconvenience_p.h>
9# include <QtGui/private/qeglplatformcontext_p.h>
14#include <KD/NV_initialize.h>
26 QMinimalEglContext(
const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display)
35 return screen->surface();
44 , m_platformContext(
nullptr)
47#ifdef QEGL_EXTRA_DEBUG
48 qWarning(
"QEglScreen %p\n",
this);
53 if (Q_UNLIKELY(!eglBindAPI(EGL_OPENGL_ES_API))) {
54 qWarning(
"Could not bind GL_ES API\n");
58 m_dpy = eglGetDisplay(display);
59 if (Q_UNLIKELY(m_dpy == EGL_NO_DISPLAY)) {
60 qWarning(
"Could not open egl display\n");
63 qWarning(
"Opened display %p\n", m_dpy);
65 if (Q_UNLIKELY(!eglInitialize(m_dpy, &major, &minor))) {
66 qWarning(
"Could not initialize egl display\n");
70 qWarning(
"Initialized display %d %d\n", major, minor);
76 eglDestroySurface(m_dpy, m_surface);
87 QSurfaceFormat platformFormat;
89 QByteArray depthString = qgetenv(
"QT_QPA_EGLFS_DEPTH");
90 if (depthString.toInt() == 16) {
91 platformFormat.setDepthBufferSize(16);
92 platformFormat.setRedBufferSize(5);
93 platformFormat.setGreenBufferSize(6);
94 platformFormat.setBlueBufferSize(5);
96 m_format = QImage::Format_RGB16;
98 platformFormat.setDepthBufferSize(24);
99 platformFormat.setStencilBufferSize(8);
100 platformFormat.setRedBufferSize(8);
101 platformFormat.setGreenBufferSize(8);
102 platformFormat.setBlueBufferSize(8);
104 m_format = QImage::Format_RGB32;
107 if (!qEnvironmentVariableIsEmpty(
"QT_QPA_EGLFS_MULTISAMPLE"))
108 platformFormat.setSamples(4);
110 EGLConfig config = q_configFromGLFormat(m_dpy, platformFormat);
112 EGLNativeWindowType eglWindow = 0;
114 if (Q_UNLIKELY(kdInitializeNV() == KD_ENOTINITIALIZED))
115 qFatal(
"Did not manage to initialize openkode");
117 KDWindow *window = kdCreateWindow(m_dpy,config,0);
119 kdRealizeWindow(window,&eglWindow);
122#ifdef QEGL_EXTRA_DEBUG
123 q_printEglConfig(m_dpy, config);
126 m_surface = eglCreateWindowSurface(m_dpy, config, eglWindow,
nullptr);
127 if (Q_UNLIKELY(m_surface == EGL_NO_SURFACE)) {
128 qWarning(
"Could not create the egl surface: error = 0x%x\n", eglGetError());
135 QEGLPlatformContext *platformContext =
new QMinimalEglContext(platformFormat,
nullptr, m_dpy);
136 m_platformContext = platformContext;
139 eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w);
140 eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h);
142 m_geometry = QRect(0,0,w,h);
148 if (m_geometry.isNull()) {
149 createAndSetPlatformContext();
161 if (m_format == QImage::Format_Invalid)
162 createAndSetPlatformContext();
168 if (!m_platformContext) {
170 that->createAndSetPlatformContext();
172 return m_platformContext;
EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) override
QMinimalEglContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display)
QMinimalEglScreen(EGLNativeDisplayType display)
QImage::Format format() const override
Reimplement in subclass to return the image format which corresponds to the screen format.
QRect geometry() const override
Reimplement in subclass to return the pixel geometry of the screen.
QPlatformOpenGLContext * platformContext() const
int depth() const override
Reimplement in subclass to return current depth of the screen.