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
qdirectfb_egl.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
9
10#include <QtGui/QOpenGLContext>
11#include <qpa/qplatformopenglcontext.h>
12#include <qpa/qwindowsysteminterface.h>
13#include <QtGui/QScreen>
14
15#include <QtGui/private/qeglplatformcontext_p.h>
16#include <QtGui/private/qeglconvenience_p.h>
17
18#include <QtGui/private/qt_egl_p.h>
19
21
22#ifdef DIRECTFB_PLATFORM_HOOKS
23extern QDirectFBEGLHooks platform_hook;
24static QDirectFBEGLHooks *hooks = &platform_hook;
25#else
26static QDirectFBEGLHooks *hooks = nullptr;
27#endif
28
29/**
30 * This provides OpenGL ES 2.0 integration with DirectFB. It assumes that
31 * one can adapt a DirectFBSurface as a EGLSurface. It might need some vendor
32 * init code in the QDirectFbScreenEGL class to initialize EGL and one might
33 * need to provide a custom QDirectFbWindowEGL::format() to return the
34 * QSurfaceFormat used by the device.
35 */
36
38public:
39 QDirectFbScreenEGL(int display);
41
42 // EGL helper
44
45private:
46 void initializeEGL();
47 void platformInit();
48 void platformDestroy();
49
50private:
51 EGLDisplay m_eglDisplay;
52};
53
55public:
56 QDirectFbWindowEGL(QWindow *tlw, QDirectFbInput *inputhandler);
58
60
61 // EGL. Subclass it instead to have different GL integrations?
63
65
66private:
67 EGLSurface m_eglSurface;
68};
69
71public:
72 QDirectFbEGLContext(QDirectFbScreenEGL *screen, QOpenGLContext *context);
73
74protected:
75 EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface);
76
77private:
78 QDirectFbScreen *m_screen;
79};
80
85
87{
88 platformDestroy();
89}
90
92{
93 if (m_eglDisplay == EGL_NO_DISPLAY)
94 initializeEGL();
95 return m_eglDisplay;
96}
97
98void QDirectFbScreenEGL::initializeEGL()
99{
100 m_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
101 if (m_eglDisplay == EGL_NO_DISPLAY)
102 return;
103
104 platformInit();
105
106 EGLint major, minor;
107 eglBindAPI(EGL_OPENGL_ES_API);
108 eglInitialize(m_eglDisplay, &major, &minor);
109 return;
110}
111
112void QDirectFbScreenEGL::platformInit()
113{
114 if (hooks)
116}
117
118void QDirectFbScreenEGL::platformDestroy()
119{
120 if (hooks)
122}
123
128
130{
131 if (m_eglSurface != EGL_NO_SURFACE) {
132 QDirectFbScreenEGL *dfbScreen;
133 dfbScreen = static_cast<QDirectFbScreenEGL*>(screen());
134 eglDestroySurface(dfbScreen->eglDisplay(), m_eglSurface);
135 }
136}
137
139{
140 // Use the default for the raster surface.
141 if (window()->surfaceType() == QSurface::RasterSurface)
143
144 Q_ASSERT(!m_dfbWindow.data());
145
146 DFBWindowDescription description;
147 memset(&description, 0, sizeof(DFBWindowDescription));
148 description.flags = DFBWindowDescriptionFlags(DWDESC_WIDTH | DWDESC_HEIGHT|
149 DWDESC_POSX | DWDESC_POSY|
150 DWDESC_PIXELFORMAT | DWDESC_SURFACE_CAPS);
151 description.width = qMax(1, window()->width());
152 description.height = qMax(1, window()->height());
153 description.posx = window()->x();
154 description.posy = window()->y();
155
156 description.surface_caps = DSCAPS_GL;
157 description.pixelformat = DSPF_RGB16;
158
159 IDirectFBDisplayLayer *layer;
160 layer = toDfbScreen(window())->dfbLayer();
161 DFBResult result = layer->CreateWindow(layer, &description, m_dfbWindow.outPtr());
162 if (result != DFB_OK)
163 DirectFBError("QDirectFbWindow: failed to create window", result);
164
165 m_dfbWindow->SetOpacity(m_dfbWindow.data(), 0xff);
166 m_inputHandler->addWindow(m_dfbWindow.data(), window());
167}
168
170{
171 if (m_eglSurface == EGL_NO_SURFACE) {
172 QDirectFbScreenEGL *dfbScreen = static_cast<QDirectFbScreenEGL *>(screen());
173 EGLConfig config = q_configFromGLFormat(dfbScreen->eglDisplay(), format(), true);
174 m_eglSurface = eglCreateWindowSurface(dfbScreen->eglDisplay(), config, dfbSurface(), NULL);
175
176 if (m_eglSurface == EGL_NO_SURFACE)
177 eglGetError();
178 }
179
180 return m_eglSurface;
181}
182
184{
185 return window()->requestedFormat();
186}
187
188
191 , m_screen(screen)
192{}
193
195{
196 QDirectFbWindowEGL *window = static_cast<QDirectFbWindowEGL*>(surface);
197 return window->eglSurface();
198}
199
200QPlatformWindow *QDirectFbIntegrationEGL::createPlatformWindow(QWindow *window) const
201{
202 QDirectFbWindow *dfbWindow = new QDirectFbWindowEGL(window, m_input.data());
203 dfbWindow->createDirectFBWindow();
204 return dfbWindow;
205}
206
207QPlatformOpenGLContext *QDirectFbIntegrationEGL::createPlatformOpenGLContext(QOpenGLContext *context) const
208{
209 QDirectFbScreenEGL *screen;
210 screen = static_cast<QDirectFbScreenEGL*>(context->screen()->handle());
211 return new QDirectFbEGLContext(screen, context);
212}
213
214void QDirectFbIntegrationEGL::initializeScreen()
215{
216 m_primaryScreen.reset(new QDirectFbScreenEGL(0));
217 QWindowSystemInterface::handleScreenAdded(m_primaryScreen.data());
218}
219
220bool QDirectFbIntegrationEGL::hasCapability(QPlatformIntegration::Capability cap) const
221{
222 // We assume that devices will have more and not less capabilities
223 if (hooks && hooks->hasCapability(cap))
224 return true;
225 return QDirectFbIntegration::hasCapability(cap);
226}
227
228QT_END_NAMESPACE
QDirectFbEGLContext(QDirectFbScreenEGL *screen, QOpenGLContext *context)
EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface)
QDirectFbScreenEGL(int display)
EGLDisplay eglDisplay()
QDirectFbScreen(int display)
EGLSurface eglSurface()
QDirectFbWindowEGL(QWindow *tlw, QDirectFbInput *inputhandler)
QSurfaceFormat format() const
Returns the actual surface format of the window.
virtual void createDirectFBWindow()
static QT_BEGIN_NAMESPACE QDirectFBEGLHooks * hooks