Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include "qminimaleglscreen.h"
5#include "qminimaleglwindow.h"
6
7#include <QtGui/private/qeglconvenience_p.h>
8#ifndef QT_NO_OPENGL
9# include <QtGui/private/qeglplatformcontext_p.h>
10#endif
11
12#ifdef Q_OPENKODE
13#include <KD/kd.h>
14#include <KD/NV_initialize.h>
15#endif //Q_OPENKODE
16
18
19// #define QEGL_EXTRA_DEBUG
20
21#ifndef QT_NO_OPENGL
22
24{
25public:
30
32 {
33 QMinimalEglWindow *window = static_cast<QMinimalEglWindow *>(surface);
34 QMinimalEglScreen *screen = static_cast<QMinimalEglScreen *>(window->screen());
35 return screen->surface();
36 }
37};
38
39#endif
40
42 : m_depth(32)
43 , m_format(QImage::Format_Invalid)
44 , m_platformContext(nullptr)
45 , m_surface(nullptr)
46{
47#ifdef QEGL_EXTRA_DEBUG
48 qWarning("QEglScreen %p\n", this);
49#endif
50
51 EGLint major, minor;
52
53 if (Q_UNLIKELY(!eglBindAPI(EGL_OPENGL_ES_API))) {
54 qWarning("Could not bind GL_ES API\n");
55 qFatal("EGL error");
56 }
57
58 m_dpy = eglGetDisplay(display);
59 if (Q_UNLIKELY(m_dpy == EGL_NO_DISPLAY)) {
60 qWarning("Could not open egl display\n");
61 qFatal("EGL error");
62 }
63 qWarning("Opened display %p\n", m_dpy);
64
65 if (Q_UNLIKELY(!eglInitialize(m_dpy, &major, &minor))) {
66 qWarning("Could not initialize egl display\n");
67 qFatal("EGL error");
68 }
69
70 qWarning("Initialized display %d %d\n", major, minor);
71}
72
74{
75 if (m_surface)
76 eglDestroySurface(m_dpy, m_surface);
77
78 eglTerminate(m_dpy);
79}
80
81void QMinimalEglScreen::createAndSetPlatformContext() const {
82 const_cast<QMinimalEglScreen *>(this)->createAndSetPlatformContext();
83}
84
85void QMinimalEglScreen::createAndSetPlatformContext()
86{
87 QSurfaceFormat platformFormat;
88
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);
95 m_depth = 16;
96 m_format = QImage::Format_RGB16;
97 } else {
98 platformFormat.setDepthBufferSize(24);
99 platformFormat.setStencilBufferSize(8);
100 platformFormat.setRedBufferSize(8);
101 platformFormat.setGreenBufferSize(8);
102 platformFormat.setBlueBufferSize(8);
103 m_depth = 32;
104 m_format = QImage::Format_RGB32;
105 }
106
107 if (!qEnvironmentVariableIsEmpty("QT_QPA_EGLFS_MULTISAMPLE"))
108 platformFormat.setSamples(4);
109
110 EGLConfig config = q_configFromGLFormat(m_dpy, platformFormat);
111
112 EGLNativeWindowType eglWindow = 0;
113#ifdef Q_OPENKODE
114 if (Q_UNLIKELY(kdInitializeNV() == KD_ENOTINITIALIZED))
115 qFatal("Did not manage to initialize openkode");
116
117 KDWindow *window = kdCreateWindow(m_dpy,config,0);
118
119 kdRealizeWindow(window,&eglWindow);
120#endif
121
122#ifdef QEGL_EXTRA_DEBUG
123 q_printEglConfig(m_dpy, config);
124#endif
125
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());
129 eglTerminate(m_dpy);
130 qFatal("EGL error");
131 }
132 // qWarning("Created surface %dx%d\n", w, h);
133
134#ifndef QT_NO_OPENGL
135 QEGLPlatformContext *platformContext = new QMinimalEglContext(platformFormat, nullptr, m_dpy);
136 m_platformContext = platformContext;
137#endif
138 EGLint w,h; // screen size detection
139 eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w);
140 eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h);
141
142 m_geometry = QRect(0,0,w,h);
143
144}
145
147{
148 if (m_geometry.isNull()) {
149 createAndSetPlatformContext();
150 }
151 return m_geometry;
152}
153
155{
156 return m_depth;
157}
158
160{
161 if (m_format == QImage::Format_Invalid)
162 createAndSetPlatformContext();
163 return m_format;
164}
165#ifndef QT_NO_OPENGL
167{
168 if (!m_platformContext) {
169 QMinimalEglScreen *that = const_cast<QMinimalEglScreen *>(this);
170 that->createAndSetPlatformContext();
171 }
172 return m_platformContext;
173}
174#endif
\inmodule QtCore
Definition qbytearray.h:57
An EGL context implementation.
\inmodule QtGui
Definition qimage.h:37
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_RGB32
Definition qimage.h:46
@ Format_Invalid
Definition qimage.h:42
@ Format_RGB16
Definition qimage.h:49
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.
The QPlatformOpenGLContext class provides an abstraction for native GL contexts.
The QPlatformSurface class provides an abstraction for a surface.
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition qrect.h:164
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
#define Q_UNLIKELY(x)
EGLConfig q_configFromGLFormat(EGLDisplay display, const QSurfaceFormat &format, bool highestPixelFormat, int surfaceType)
void q_printEglConfig(EGLDisplay display, EGLConfig config)
EGLConfig config
typedef EGLSurface(EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC)(EGLDisplay dpy
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
#define qWarning
Definition qlogging.h:166
#define qFatal
Definition qlogging.h:168
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
QScreen * screen
[1]
Definition main.cpp:29
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
QObject::connect nullptr
aWidget window() -> setWindowTitle("New Window Title")
[2]