Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qminimaleglscreen.cpp
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
7
8#include <QtGui/private/qeglconvenience_p.h>
9#ifndef QT_NO_OPENGL
10# include <QtGui/private/qeglplatformcontext_p.h>
11#endif
12
13#ifdef Q_OPENKODE
14#include <KD/kd.h>
15#include <KD/NV_initialize.h>
16#endif //Q_OPENKODE
17
19
20// #define QEGL_EXTRA_DEBUG
21
22#ifndef QT_NO_OPENGL
23
25{
26public:
27 QMinimalEglContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display)
29 {
30 }
31
32 EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) override
33 {
34 QMinimalEglWindow *window = static_cast<QMinimalEglWindow *>(surface);
35 QMinimalEglScreen *screen = static_cast<QMinimalEglScreen *>(window->screen());
36 return screen->surface();
37 }
38};
39
40#endif
41
42QMinimalEglScreen::QMinimalEglScreen(EGLNativeDisplayType display)
43 : m_depth(32)
45 , m_platformContext(nullptr)
46 , m_surface(nullptr)
47{
48#ifdef QEGL_EXTRA_DEBUG
49 qWarning("QEglScreen %p\n", this);
50#endif
51
52 EGLint major, minor;
53
54 if (Q_UNLIKELY(!eglBindAPI(EGL_OPENGL_ES_API))) {
55 qWarning("Could not bind GL_ES API\n");
56 qFatal("EGL error");
57 }
58
59 m_dpy = eglGetDisplay(display);
60 if (Q_UNLIKELY(m_dpy == EGL_NO_DISPLAY)) {
61 qWarning("Could not open egl display\n");
62 qFatal("EGL error");
63 }
64 qWarning("Opened display %p\n", m_dpy);
65
66 if (Q_UNLIKELY(!eglInitialize(m_dpy, &major, &minor))) {
67 qWarning("Could not initialize egl display\n");
68 qFatal("EGL error");
69 }
70
71 qWarning("Initialized display %d %d\n", major, minor);
72}
73
75{
76 if (m_surface)
77 eglDestroySurface(m_dpy, m_surface);
78
79 eglTerminate(m_dpy);
80}
81
82void QMinimalEglScreen::createAndSetPlatformContext() const {
83 const_cast<QMinimalEglScreen *>(this)->createAndSetPlatformContext();
84}
85
86void QMinimalEglScreen::createAndSetPlatformContext()
87{
88 QSurfaceFormat platformFormat;
89
90 QByteArray depthString = qgetenv("QT_QPA_EGLFS_DEPTH");
91 if (depthString.toInt() == 16) {
92 platformFormat.setDepthBufferSize(16);
93 platformFormat.setRedBufferSize(5);
94 platformFormat.setGreenBufferSize(6);
95 platformFormat.setBlueBufferSize(5);
96 m_depth = 16;
97 m_format = QImage::Format_RGB16;
98 } else {
99 platformFormat.setDepthBufferSize(24);
100 platformFormat.setStencilBufferSize(8);
101 platformFormat.setRedBufferSize(8);
102 platformFormat.setGreenBufferSize(8);
103 platformFormat.setBlueBufferSize(8);
104 m_depth = 32;
105 m_format = QImage::Format_RGB32;
106 }
107
108 if (!qEnvironmentVariableIsEmpty("QT_QPA_EGLFS_MULTISAMPLE"))
109 platformFormat.setSamples(4);
110
111 EGLConfig config = q_configFromGLFormat(m_dpy, platformFormat);
112
113 EGLNativeWindowType eglWindow = 0;
114#ifdef Q_OPENKODE
115 if (Q_UNLIKELY(kdInitializeNV() == KD_ENOTINITIALIZED))
116 qFatal("Did not manage to initialize openkode");
117
118 KDWindow *window = kdCreateWindow(m_dpy,config,0);
119
120 kdRealizeWindow(window,&eglWindow);
121#endif
122
123#ifdef QEGL_EXTRA_DEBUG
124 q_printEglConfig(m_dpy, config);
125#endif
126
127 m_surface = eglCreateWindowSurface(m_dpy, config, eglWindow, nullptr);
128 if (Q_UNLIKELY(m_surface == EGL_NO_SURFACE)) {
129 qWarning("Could not create the egl surface: error = 0x%x\n", eglGetError());
130 eglTerminate(m_dpy);
131 qFatal("EGL error");
132 }
133 // qWarning("Created surface %dx%d\n", w, h);
134
135#ifndef QT_NO_OPENGL
136 QEGLPlatformContext *platformContext = new QMinimalEglContext(platformFormat, nullptr, m_dpy);
137 m_platformContext = platformContext;
138#endif
139 EGLint w,h; // screen size detection
140 eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w);
141 eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h);
142
143 m_geometry = QRect(0,0,w,h);
144
145}
146
148{
149 if (m_geometry.isNull()) {
150 createAndSetPlatformContext();
151 }
152 return m_geometry;
153}
154
156{
157 return m_depth;
158}
159
161{
162 if (m_format == QImage::Format_Invalid)
163 createAndSetPlatformContext();
164 return m_format;
165}
166#ifndef QT_NO_OPENGL
167QPlatformOpenGLContext *QMinimalEglScreen::platformContext() const
168{
169 if (!m_platformContext) {
170 QMinimalEglScreen *that = const_cast<QMinimalEglScreen *>(this);
171 that->createAndSetPlatformContext();
172 }
173 return m_platformContext;
174}
175#endif
176QT_END_NAMESPACE
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.
Combined button and popup list for selecting options.