| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/eglconvenience/qeglplatformcontext.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the plugins of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "qeglplatformcontext_p.h" | - | ||||||||||||
| 41 | #include "qeglconvenience_p.h" | - | ||||||||||||
| 42 | #include "qeglpbuffer_p.h" | - | ||||||||||||
| 43 | #include <qpa/qplatformwindow.h> | - | ||||||||||||
| 44 | #include <QOpenGLContext> | - | ||||||||||||
| 45 | #include <QtPlatformHeaders/QEGLNativeContext> | - | ||||||||||||
| 46 | #include <QDebug> | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | #ifdef Q_OS_ANDROID | - | ||||||||||||
| 49 | #include <QtCore/private/qjnihelpers_p.h> | - | ||||||||||||
| 50 | #endif | - | ||||||||||||
| 51 | #ifndef Q_OS_WIN | - | ||||||||||||
| 52 | #include <dlfcn.h> | - | ||||||||||||
| 53 | #endif | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | /*! | - | ||||||||||||
| 58 | \class QEGLPlatformContext | - | ||||||||||||
| 59 | \brief An EGL context implementation. | - | ||||||||||||
| 60 | \since 5.2 | - | ||||||||||||
| 61 | \internal | - | ||||||||||||
| 62 | \ingroup qpa | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | Implement QPlatformOpenGLContext using EGL. To use it in platform | - | ||||||||||||
| 65 | plugins a subclass must be created since | - | ||||||||||||
| 66 | eglSurfaceForPlatformSurface() has to be reimplemented. This | - | ||||||||||||
| 67 | function is used for mapping platform surfaces (windows) to EGL | - | ||||||||||||
| 68 | surfaces and is necessary since different platform plugins may | - | ||||||||||||
| 69 | have different ways of handling native windows (for example, a | - | ||||||||||||
| 70 | plugin may choose not to back every platform window by a real EGL | - | ||||||||||||
| 71 | surface). Other than that, no further customization is necessary. | - | ||||||||||||
| 72 | */ | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | // Constants from EGL_KHR_create_context | - | ||||||||||||
| 75 | #ifndef EGL_CONTEXT_MINOR_VERSION_KHR | - | ||||||||||||
| 76 | #define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB | - | ||||||||||||
| 77 | #endif | - | ||||||||||||
| 78 | #ifndef EGL_CONTEXT_FLAGS_KHR | - | ||||||||||||
| 79 | #define EGL_CONTEXT_FLAGS_KHR 0x30FC | - | ||||||||||||
| 80 | #endif | - | ||||||||||||
| 81 | #ifndef EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR | - | ||||||||||||
| 82 | #define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD | - | ||||||||||||
| 83 | #endif | - | ||||||||||||
| 84 | #ifndef EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR | - | ||||||||||||
| 85 | #define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001 | - | ||||||||||||
| 86 | #endif | - | ||||||||||||
| 87 | #ifndef EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR | - | ||||||||||||
| 88 | #define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002 | - | ||||||||||||
| 89 | #endif | - | ||||||||||||
| 90 | #ifndef EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR | - | ||||||||||||
| 91 | #define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001 | - | ||||||||||||
| 92 | #endif | - | ||||||||||||
| 93 | #ifndef EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR | - | ||||||||||||
| 94 | #define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002 | - | ||||||||||||
| 95 | #endif | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | // Constants for OpenGL which are not available in the ES headers. | - | ||||||||||||
| 98 | #ifndef GL_CONTEXT_FLAGS | - | ||||||||||||
| 99 | #define GL_CONTEXT_FLAGS 0x821E | - | ||||||||||||
| 100 | #endif | - | ||||||||||||
| 101 | #ifndef GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT | - | ||||||||||||
| 102 | #define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x0001 | - | ||||||||||||
| 103 | #endif | - | ||||||||||||
| 104 | #ifndef GL_CONTEXT_FLAG_DEBUG_BIT | - | ||||||||||||
| 105 | #define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002 | - | ||||||||||||
| 106 | #endif | - | ||||||||||||
| 107 | #ifndef GL_CONTEXT_PROFILE_MASK | - | ||||||||||||
| 108 | #define GL_CONTEXT_PROFILE_MASK 0x9126 | - | ||||||||||||
| 109 | #endif | - | ||||||||||||
| 110 | #ifndef GL_CONTEXT_CORE_PROFILE_BIT | - | ||||||||||||
| 111 | #define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001 | - | ||||||||||||
| 112 | #endif | - | ||||||||||||
| 113 | #ifndef GL_CONTEXT_COMPATIBILITY_PROFILE_BIT | - | ||||||||||||
| 114 | #define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002 | - | ||||||||||||
| 115 | #endif | - | ||||||||||||
| 116 | - | |||||||||||||
| 117 | QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, | - | ||||||||||||
| 118 | EGLConfig *config, const QVariant &nativeHandle, Flags flags) | - | ||||||||||||
| 119 | : m_eglDisplay(display) | - | ||||||||||||
| 120 | , m_swapInterval(-1) | - | ||||||||||||
| 121 | , m_swapIntervalEnvChecked(false) | - | ||||||||||||
| 122 | , m_swapIntervalFromEnv(-1) | - | ||||||||||||
| 123 | , m_flags(flags) | - | ||||||||||||
| 124 | { | - | ||||||||||||
| 125 | if (nativeHandle.isNull()) {
| 0 | ||||||||||||
| 126 | m_eglConfig = config ? *config : q_configFromGLFormat(display, format);
| 0 | ||||||||||||
| 127 | m_ownsContext = true; | - | ||||||||||||
| 128 | init(format, share); | - | ||||||||||||
| 129 | } else { never executed: end of block | 0 | ||||||||||||
| 130 | m_ownsContext = false; | - | ||||||||||||
| 131 | adopt(nativeHandle, share); | - | ||||||||||||
| 132 | } never executed: end of block | 0 | ||||||||||||
| 133 | } | - | ||||||||||||
| 134 | - | |||||||||||||
| 135 | void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLContext *share) | - | ||||||||||||
| 136 | { | - | ||||||||||||
| 137 | m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig); | - | ||||||||||||
| 138 | // m_format now has the renderableType() resolved (it cannot be Default anymore) | - | ||||||||||||
| 139 | // but does not yet contain version, profile, options. | - | ||||||||||||
| 140 | m_shareContext = share ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0;
| 0 | ||||||||||||
| 141 | - | |||||||||||||
| 142 | QVector<EGLint> contextAttrs; | - | ||||||||||||
| 143 | contextAttrs.append(EGL_CONTEXT_CLIENT_VERSION); | - | ||||||||||||
| 144 | contextAttrs.append(format.majorVersion()); | - | ||||||||||||
| 145 | const bool hasKHRCreateContext = q_hasEglExtension(m_eglDisplay, "EGL_KHR_create_context"); | - | ||||||||||||
| 146 | if (hasKHRCreateContext) {
| 0 | ||||||||||||
| 147 | contextAttrs.append(EGL_CONTEXT_MINOR_VERSION_KHR); | - | ||||||||||||
| 148 | contextAttrs.append(format.minorVersion()); | - | ||||||||||||
| 149 | int flags = 0; | - | ||||||||||||
| 150 | // The debug bit is supported both for OpenGL and OpenGL ES. | - | ||||||||||||
| 151 | if (format.testOption(QSurfaceFormat::DebugContext))
| 0 | ||||||||||||
| 152 | flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; never executed: flags |= 0x00000001; | 0 | ||||||||||||
| 153 | // The fwdcompat bit is only for OpenGL 3.0+. | - | ||||||||||||
| 154 | if (m_format.renderableType() == QSurfaceFormat::OpenGL
| 0 | ||||||||||||
| 155 | && format.majorVersion() >= 3
| 0 | ||||||||||||
| 156 | && !format.testOption(QSurfaceFormat::DeprecatedFunctions))
| 0 | ||||||||||||
| 157 | flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; never executed: flags |= 0x00000002; | 0 | ||||||||||||
| 158 | if (flags) {
| 0 | ||||||||||||
| 159 | contextAttrs.append(EGL_CONTEXT_FLAGS_KHR); | - | ||||||||||||
| 160 | contextAttrs.append(flags); | - | ||||||||||||
| 161 | } never executed: end of block | 0 | ||||||||||||
| 162 | // Profiles are OpenGL only and mandatory in 3.2+. The value is silently ignored for < 3.2. | - | ||||||||||||
| 163 | if (m_format.renderableType() == QSurfaceFormat::OpenGL) {
| 0 | ||||||||||||
| 164 | contextAttrs.append(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR); | - | ||||||||||||
| 165 | contextAttrs.append(format.profile() == QSurfaceFormat::CoreProfile | - | ||||||||||||
| 166 | ? EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR | - | ||||||||||||
| 167 | : EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR); | - | ||||||||||||
| 168 | } never executed: end of block | 0 | ||||||||||||
| 169 | } never executed: end of block | 0 | ||||||||||||
| 170 | contextAttrs.append(EGL_NONE); | - | ||||||||||||
| 171 | m_contextAttrs = contextAttrs; | - | ||||||||||||
| 172 | - | |||||||||||||
| 173 | switch (m_format.renderableType()) { | - | ||||||||||||
| 174 | case QSurfaceFormat::OpenVG: never executed: case QSurfaceFormat::OpenVG: | 0 | ||||||||||||
| 175 | m_api = EGL_OPENVG_API; | - | ||||||||||||
| 176 | break; never executed: break; | 0 | ||||||||||||
| 177 | #ifdef EGL_VERSION_1_4 | - | ||||||||||||
| 178 | case QSurfaceFormat::OpenGL: never executed: case QSurfaceFormat::OpenGL: | 0 | ||||||||||||
| 179 | m_api = EGL_OPENGL_API; | - | ||||||||||||
| 180 | break; never executed: break; | 0 | ||||||||||||
| 181 | #endif // EGL_VERSION_1_4 | - | ||||||||||||
| 182 | default: never executed: default: | 0 | ||||||||||||
| 183 | m_api = EGL_OPENGL_ES_API; | - | ||||||||||||
| 184 | break; never executed: break; | 0 | ||||||||||||
| 185 | } | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | eglBindAPI(m_api); | - | ||||||||||||
| 188 | m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, m_shareContext, contextAttrs.constData()); | - | ||||||||||||
| 189 | if (m_eglContext == EGL_NO_CONTEXT && m_shareContext != EGL_NO_CONTEXT) {
| 0 | ||||||||||||
| 190 | m_shareContext = 0; | - | ||||||||||||
| 191 | m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, 0, contextAttrs.constData()); | - | ||||||||||||
| 192 | } never executed: end of block | 0 | ||||||||||||
| 193 | - | |||||||||||||
| 194 | if (m_eglContext == EGL_NO_CONTEXT) {
| 0 | ||||||||||||
| 195 | qWarning("QEGLPlatformContext: Failed to create context: %x", eglGetError()); | - | ||||||||||||
| 196 | return; never executed: return; | 0 | ||||||||||||
| 197 | } | - | ||||||||||||
| 198 | - | |||||||||||||
| 199 | static const bool printConfig = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DEBUG"); | - | ||||||||||||
| 200 | if (printConfig) {
| 0 | ||||||||||||
| 201 | qDebug() << "Created context for format" << format << "with config:"; | - | ||||||||||||
| 202 | q_printEglConfig(m_eglDisplay, m_eglConfig); | - | ||||||||||||
| 203 | } never executed: end of block | 0 | ||||||||||||
| 204 | - | |||||||||||||
| 205 | // Cannot just call updateFormatFromGL() since it relies on virtuals. Defer it to initialize(). | - | ||||||||||||
| 206 | } never executed: end of block | 0 | ||||||||||||
| 207 | - | |||||||||||||
| 208 | void QEGLPlatformContext::adopt(const QVariant &nativeHandle, QPlatformOpenGLContext *share) | - | ||||||||||||
| 209 | { | - | ||||||||||||
| 210 | if (!nativeHandle.canConvert<QEGLNativeContext>()) {
| 0 | ||||||||||||
| 211 | qWarning("QEGLPlatformContext: Requires a QEGLNativeContext"); | - | ||||||||||||
| 212 | return; never executed: return; | 0 | ||||||||||||
| 213 | } | - | ||||||||||||
| 214 | QEGLNativeContext handle = nativeHandle.value<QEGLNativeContext>(); | - | ||||||||||||
| 215 | EGLContext context = handle.context(); | - | ||||||||||||
| 216 | if (!context) {
| 0 | ||||||||||||
| 217 | qWarning("QEGLPlatformContext: No EGLContext given"); | - | ||||||||||||
| 218 | return; never executed: return; | 0 | ||||||||||||
| 219 | } | - | ||||||||||||
| 220 | - | |||||||||||||
| 221 | // A context belonging to a given EGLDisplay cannot be used with another one. | - | ||||||||||||
| 222 | if (handle.display() != m_eglDisplay) {
| 0 | ||||||||||||
| 223 | qWarning("QEGLPlatformContext: Cannot adopt context from different display"); | - | ||||||||||||
| 224 | return; never executed: return; | 0 | ||||||||||||
| 225 | } | - | ||||||||||||
| 226 | - | |||||||||||||
| 227 | // Figure out the EGLConfig. | - | ||||||||||||
| 228 | EGLint value = 0; | - | ||||||||||||
| 229 | eglQueryContext(m_eglDisplay, context, EGL_CONFIG_ID, &value); | - | ||||||||||||
| 230 | EGLint n = 0; | - | ||||||||||||
| 231 | EGLConfig cfg; | - | ||||||||||||
| 232 | const EGLint attribs[] = { EGL_CONFIG_ID, value, EGL_NONE }; | - | ||||||||||||
| 233 | if (eglChooseConfig(m_eglDisplay, attribs, &cfg, 1, &n) && n == 1) {
| 0 | ||||||||||||
| 234 | m_eglConfig = cfg; | - | ||||||||||||
| 235 | m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig); | - | ||||||||||||
| 236 | } else { never executed: end of block | 0 | ||||||||||||
| 237 | qWarning("QEGLPlatformContext: Failed to get framebuffer configuration for context"); | - | ||||||||||||
| 238 | } never executed: end of block | 0 | ||||||||||||
| 239 | - | |||||||||||||
| 240 | // Fetch client API type. | - | ||||||||||||
| 241 | value = 0; | - | ||||||||||||
| 242 | eglQueryContext(m_eglDisplay, context, EGL_CONTEXT_CLIENT_TYPE, &value); | - | ||||||||||||
| 243 | if (value == EGL_OPENGL_API || value == EGL_OPENGL_ES_API) {
| 0 | ||||||||||||
| 244 | m_api = value; | - | ||||||||||||
| 245 | eglBindAPI(m_api); | - | ||||||||||||
| 246 | } else { never executed: end of block | 0 | ||||||||||||
| 247 | qWarning("QEGLPlatformContext: Failed to get client API type"); | - | ||||||||||||
| 248 | m_api = EGL_OPENGL_ES_API; | - | ||||||||||||
| 249 | } never executed: end of block | 0 | ||||||||||||
| 250 | - | |||||||||||||
| 251 | m_eglContext = context; | - | ||||||||||||
| 252 | m_shareContext = share ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0;
| 0 | ||||||||||||
| 253 | updateFormatFromGL(); | - | ||||||||||||
| 254 | } never executed: end of block | 0 | ||||||||||||
| 255 | - | |||||||||||||
| 256 | void QEGLPlatformContext::initialize() | - | ||||||||||||
| 257 | { | - | ||||||||||||
| 258 | if (m_eglContext != EGL_NO_CONTEXT)
| 0 | ||||||||||||
| 259 | updateFormatFromGL(); never executed: updateFormatFromGL(); | 0 | ||||||||||||
| 260 | } never executed: end of block | 0 | ||||||||||||
| 261 | - | |||||||||||||
| 262 | // Base implementation for pbuffers. Subclasses will handle the specialized cases for | - | ||||||||||||
| 263 | // platforms without pbuffers. | - | ||||||||||||
| 264 | EGLSurface QEGLPlatformContext::createTemporaryOffscreenSurface() | - | ||||||||||||
| 265 | { | - | ||||||||||||
| 266 | // Make the context current to ensure the GL version query works. This needs a surface too. | - | ||||||||||||
| 267 | const EGLint pbufferAttributes[] = { | - | ||||||||||||
| 268 | EGL_WIDTH, 1, | - | ||||||||||||
| 269 | EGL_HEIGHT, 1, | - | ||||||||||||
| 270 | EGL_LARGEST_PBUFFER, EGL_FALSE, | - | ||||||||||||
| 271 | EGL_NONE | - | ||||||||||||
| 272 | }; | - | ||||||||||||
| 273 | - | |||||||||||||
| 274 | // Cannot just pass m_eglConfig because it may not be suitable for pbuffers. Instead, | - | ||||||||||||
| 275 | // do what QEGLPbuffer would do: request a config with the same attributes but with | - | ||||||||||||
| 276 | // PBUFFER_BIT set. | - | ||||||||||||
| 277 | EGLConfig config = q_configFromGLFormat(m_eglDisplay, m_format, false, EGL_PBUFFER_BIT); | - | ||||||||||||
| 278 | - | |||||||||||||
| 279 | return eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes); never executed: return eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes); | 0 | ||||||||||||
| 280 | } | - | ||||||||||||
| 281 | - | |||||||||||||
| 282 | void QEGLPlatformContext::destroyTemporaryOffscreenSurface(EGLSurface surface) | - | ||||||||||||
| 283 | { | - | ||||||||||||
| 284 | eglDestroySurface(m_eglDisplay, surface); | - | ||||||||||||
| 285 | } never executed: end of block | 0 | ||||||||||||
| 286 | - | |||||||||||||
| 287 | void QEGLPlatformContext::runGLChecks() | - | ||||||||||||
| 288 | { | - | ||||||||||||
| 289 | // Nothing to do here, subclasses may override in order to perform OpenGL | - | ||||||||||||
| 290 | // queries needing a context. | - | ||||||||||||
| 291 | } | - | ||||||||||||
| 292 | - | |||||||||||||
| 293 | void QEGLPlatformContext::updateFormatFromGL() | - | ||||||||||||
| 294 | { | - | ||||||||||||
| 295 | #ifndef QT_NO_OPENGL | - | ||||||||||||
| 296 | // Have to save & restore to prevent QOpenGLContext::currentContext() from becoming | - | ||||||||||||
| 297 | // inconsistent after QOpenGLContext::create(). | - | ||||||||||||
| 298 | EGLDisplay prevDisplay = eglGetCurrentDisplay(); | - | ||||||||||||
| 299 | if (prevDisplay == EGL_NO_DISPLAY) // when no context is current
| 0 | ||||||||||||
| 300 | prevDisplay = m_eglDisplay; never executed: prevDisplay = m_eglDisplay; | 0 | ||||||||||||
| 301 | EGLContext prevContext = eglGetCurrentContext(); | - | ||||||||||||
| 302 | EGLSurface prevSurfaceDraw = eglGetCurrentSurface(EGL_DRAW); | - | ||||||||||||
| 303 | EGLSurface prevSurfaceRead = eglGetCurrentSurface(EGL_READ); | - | ||||||||||||
| 304 | - | |||||||||||||
| 305 | // Rely on the surfaceless extension, if available. This is beneficial since we can | - | ||||||||||||
| 306 | // avoid creating an extra pbuffer surface which is apparently troublesome with some | - | ||||||||||||
| 307 | // drivers (Mesa) when certain attributes are present (multisampling). | - | ||||||||||||
| 308 | EGLSurface tempSurface = EGL_NO_SURFACE; | - | ||||||||||||
| 309 | EGLContext tempContext = EGL_NO_CONTEXT; | - | ||||||||||||
| 310 | if (m_flags.testFlag(NoSurfaceless) || !q_hasEglExtension(m_eglDisplay, "EGL_KHR_surfaceless_context"))
| 0 | ||||||||||||
| 311 | tempSurface = createTemporaryOffscreenSurface(); never executed: tempSurface = createTemporaryOffscreenSurface(); | 0 | ||||||||||||
| 312 | - | |||||||||||||
| 313 | EGLBoolean ok = eglMakeCurrent(m_eglDisplay, tempSurface, tempSurface, m_eglContext); | - | ||||||||||||
| 314 | if (!ok) {
| 0 | ||||||||||||
| 315 | EGLConfig config = q_configFromGLFormat(m_eglDisplay, m_format, false, EGL_PBUFFER_BIT); | - | ||||||||||||
| 316 | tempContext = eglCreateContext(m_eglDisplay, config, 0, m_contextAttrs.constData()); | - | ||||||||||||
| 317 | if (tempContext != EGL_NO_CONTEXT)
| 0 | ||||||||||||
| 318 | ok = eglMakeCurrent(m_eglDisplay, tempSurface, tempSurface, tempContext); never executed: ok = eglMakeCurrent(m_eglDisplay, tempSurface, tempSurface, tempContext); | 0 | ||||||||||||
| 319 | } never executed: end of block | 0 | ||||||||||||
| 320 | if (ok) {
| 0 | ||||||||||||
| 321 | if (m_format.renderableType() == QSurfaceFormat::OpenGL
| 0 | ||||||||||||
| 322 | || m_format.renderableType() == QSurfaceFormat::OpenGLES) {
| 0 | ||||||||||||
| 323 | const GLubyte *s = glGetString(GL_VERSION); | - | ||||||||||||
| 324 | if (s) {
| 0 | ||||||||||||
| 325 | QByteArray version = QByteArray(reinterpret_cast<const char *>(s)); | - | ||||||||||||
| 326 | int major, minor; | - | ||||||||||||
| 327 | if (QPlatformOpenGLContext::parseOpenGLVersion(version, major, minor)) {
| 0 | ||||||||||||
| 328 | #ifdef Q_OS_ANDROID | - | ||||||||||||
| 329 | // Some Android 4.2.2 devices report OpenGL ES 3.0 without the functions being available. | - | ||||||||||||
| 330 | static int apiLevel = QtAndroidPrivate::androidSdkVersion(); | - | ||||||||||||
| 331 | if (apiLevel <= 17 && major >= 3) { | - | ||||||||||||
| 332 | major = 2; | - | ||||||||||||
| 333 | minor = 0; | - | ||||||||||||
| 334 | } | - | ||||||||||||
| 335 | #endif | - | ||||||||||||
| 336 | m_format.setMajorVersion(major); | - | ||||||||||||
| 337 | m_format.setMinorVersion(minor); | - | ||||||||||||
| 338 | } never executed: end of block | 0 | ||||||||||||
| 339 | } never executed: end of block | 0 | ||||||||||||
| 340 | m_format.setProfile(QSurfaceFormat::NoProfile); | - | ||||||||||||
| 341 | m_format.setOptions(QSurfaceFormat::FormatOptions()); | - | ||||||||||||
| 342 | if (m_format.renderableType() == QSurfaceFormat::OpenGL) {
| 0 | ||||||||||||
| 343 | // Check profile and options. | - | ||||||||||||
| 344 | if (m_format.majorVersion() < 3) {
| 0 | ||||||||||||
| 345 | m_format.setOption(QSurfaceFormat::DeprecatedFunctions); | - | ||||||||||||
| 346 | } else { never executed: end of block | 0 | ||||||||||||
| 347 | GLint value = 0; | - | ||||||||||||
| 348 | glGetIntegerv(GL_CONTEXT_FLAGS, &value); | - | ||||||||||||
| 349 | if (!(value & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT))
| 0 | ||||||||||||
| 350 | m_format.setOption(QSurfaceFormat::DeprecatedFunctions); never executed: m_format.setOption(QSurfaceFormat::DeprecatedFunctions); | 0 | ||||||||||||
| 351 | if (value & GL_CONTEXT_FLAG_DEBUG_BIT)
| 0 | ||||||||||||
| 352 | m_format.setOption(QSurfaceFormat::DebugContext); never executed: m_format.setOption(QSurfaceFormat::DebugContext); | 0 | ||||||||||||
| 353 | if (m_format.version() >= qMakePair(3, 2)) {
| 0 | ||||||||||||
| 354 | value = 0; | - | ||||||||||||
| 355 | glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &value); | - | ||||||||||||
| 356 | if (value & GL_CONTEXT_CORE_PROFILE_BIT)
| 0 | ||||||||||||
| 357 | m_format.setProfile(QSurfaceFormat::CoreProfile); never executed: m_format.setProfile(QSurfaceFormat::CoreProfile); | 0 | ||||||||||||
| 358 | else if (value & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
| 0 | ||||||||||||
| 359 | m_format.setProfile(QSurfaceFormat::CompatibilityProfile); never executed: m_format.setProfile(QSurfaceFormat::CompatibilityProfile); | 0 | ||||||||||||
| 360 | } never executed: end of block | 0 | ||||||||||||
| 361 | } never executed: end of block | 0 | ||||||||||||
| 362 | } | - | ||||||||||||
| 363 | } never executed: end of block | 0 | ||||||||||||
| 364 | runGLChecks(); | - | ||||||||||||
| 365 | eglMakeCurrent(prevDisplay, prevSurfaceDraw, prevSurfaceRead, prevContext); | - | ||||||||||||
| 366 | } else { never executed: end of block | 0 | ||||||||||||
| 367 | qWarning("QEGLPlatformContext: Failed to make temporary surface current, format not updated (%x)", eglGetError()); | - | ||||||||||||
| 368 | } never executed: end of block | 0 | ||||||||||||
| 369 | if (tempSurface != EGL_NO_SURFACE)
| 0 | ||||||||||||
| 370 | destroyTemporaryOffscreenSurface(tempSurface); never executed: destroyTemporaryOffscreenSurface(tempSurface); | 0 | ||||||||||||
| 371 | if (tempContext != EGL_NO_CONTEXT)
| 0 | ||||||||||||
| 372 | eglDestroyContext(m_eglDisplay, tempContext); never executed: eglDestroyContext(m_eglDisplay, tempContext); | 0 | ||||||||||||
| 373 | #endif // QT_NO_OPENGL | - | ||||||||||||
| 374 | } never executed: end of block | 0 | ||||||||||||
| 375 | - | |||||||||||||
| 376 | bool QEGLPlatformContext::makeCurrent(QPlatformSurface *surface) | - | ||||||||||||
| 377 | { | - | ||||||||||||
| 378 | Q_ASSERT(surface->surface()->supportsOpenGL()); | - | ||||||||||||
| 379 | - | |||||||||||||
| 380 | eglBindAPI(m_api); | - | ||||||||||||
| 381 | - | |||||||||||||
| 382 | EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface); | - | ||||||||||||
| 383 | - | |||||||||||||
| 384 | // shortcut: on some GPUs, eglMakeCurrent is not a cheap operation | - | ||||||||||||
| 385 | if (eglGetCurrentContext() == m_eglContext &&
| 0 | ||||||||||||
| 386 | eglGetCurrentDisplay() == m_eglDisplay &&
| 0 | ||||||||||||
| 387 | eglGetCurrentSurface(EGL_READ) == eglSurface &&
| 0 | ||||||||||||
| 388 | eglGetCurrentSurface(EGL_DRAW) == eglSurface) {
| 0 | ||||||||||||
| 389 | return true; never executed: return true; | 0 | ||||||||||||
| 390 | } | - | ||||||||||||
| 391 | - | |||||||||||||
| 392 | const bool ok = eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_eglContext); | - | ||||||||||||
| 393 | if (ok) {
| 0 | ||||||||||||
| 394 | if (!m_swapIntervalEnvChecked) {
| 0 | ||||||||||||
| 395 | m_swapIntervalEnvChecked = true; | - | ||||||||||||
| 396 | if (qEnvironmentVariableIsSet("QT_QPA_EGLFS_SWAPINTERVAL")) {
| 0 | ||||||||||||
| 397 | QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL"); | - | ||||||||||||
| 398 | bool intervalOk; | - | ||||||||||||
| 399 | const int swapInterval = swapIntervalString.toInt(&intervalOk); | - | ||||||||||||
| 400 | if (intervalOk)
| 0 | ||||||||||||
| 401 | m_swapIntervalFromEnv = swapInterval; never executed: m_swapIntervalFromEnv = swapInterval; | 0 | ||||||||||||
| 402 | } never executed: end of block | 0 | ||||||||||||
| 403 | } never executed: end of block | 0 | ||||||||||||
| 404 | const int requestedSwapInterval = m_swapIntervalFromEnv >= 0
| 0 | ||||||||||||
| 405 | ? m_swapIntervalFromEnv | - | ||||||||||||
| 406 | : surface->format().swapInterval(); | - | ||||||||||||
| 407 | if (requestedSwapInterval >= 0 && m_swapInterval != requestedSwapInterval) {
| 0 | ||||||||||||
| 408 | m_swapInterval = requestedSwapInterval; | - | ||||||||||||
| 409 | if (eglSurface != EGL_NO_SURFACE) // skip if using surfaceless context
| 0 | ||||||||||||
| 410 | eglSwapInterval(eglDisplay(), m_swapInterval); never executed: eglSwapInterval(eglDisplay(), m_swapInterval); | 0 | ||||||||||||
| 411 | } never executed: end of block | 0 | ||||||||||||
| 412 | } else { never executed: end of block | 0 | ||||||||||||
| 413 | qWarning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError()); | - | ||||||||||||
| 414 | } never executed: end of block | 0 | ||||||||||||
| 415 | - | |||||||||||||
| 416 | return ok; never executed: return ok; | 0 | ||||||||||||
| 417 | } | - | ||||||||||||
| 418 | - | |||||||||||||
| 419 | QEGLPlatformContext::~QEGLPlatformContext() | - | ||||||||||||
| 420 | { | - | ||||||||||||
| 421 | if (m_ownsContext && m_eglContext != EGL_NO_CONTEXT)
| 0 | ||||||||||||
| 422 | eglDestroyContext(m_eglDisplay, m_eglContext); never executed: eglDestroyContext(m_eglDisplay, m_eglContext); | 0 | ||||||||||||
| 423 | - | |||||||||||||
| 424 | m_eglContext = EGL_NO_CONTEXT; | - | ||||||||||||
| 425 | } never executed: end of block | 0 | ||||||||||||
| 426 | - | |||||||||||||
| 427 | void QEGLPlatformContext::doneCurrent() | - | ||||||||||||
| 428 | { | - | ||||||||||||
| 429 | eglBindAPI(m_api); | - | ||||||||||||
| 430 | bool ok = eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); | - | ||||||||||||
| 431 | if (!ok)
| 0 | ||||||||||||
| 432 | qWarning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError()); never executed: QMessageLogger(__FILE__, 432, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError()); | 0 | ||||||||||||
| 433 | } never executed: end of block | 0 | ||||||||||||
| 434 | - | |||||||||||||
| 435 | void QEGLPlatformContext::swapBuffers(QPlatformSurface *surface) | - | ||||||||||||
| 436 | { | - | ||||||||||||
| 437 | eglBindAPI(m_api); | - | ||||||||||||
| 438 | EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface); | - | ||||||||||||
| 439 | if (eglSurface != EGL_NO_SURFACE) { // skip if using surfaceless context
| 0 | ||||||||||||
| 440 | bool ok = eglSwapBuffers(m_eglDisplay, eglSurface); | - | ||||||||||||
| 441 | if (!ok)
| 0 | ||||||||||||
| 442 | qWarning("QEGLPlatformContext: eglSwapBuffers failed: %x", eglGetError()); never executed: QMessageLogger(__FILE__, 442, __PRETTY_FUNCTION__).warning("QEGLPlatformContext: eglSwapBuffers failed: %x", eglGetError()); | 0 | ||||||||||||
| 443 | } never executed: end of block | 0 | ||||||||||||
| 444 | } never executed: end of block | 0 | ||||||||||||
| 445 | - | |||||||||||||
| 446 | QFunctionPointer QEGLPlatformContext::getProcAddress(const char *procName) | - | ||||||||||||
| 447 | { | - | ||||||||||||
| 448 | eglBindAPI(m_api); | - | ||||||||||||
| 449 | QFunctionPointer proc = (QFunctionPointer) eglGetProcAddress(procName); | - | ||||||||||||
| 450 | #if !defined(Q_OS_WIN) && !defined(Q_OS_INTEGRITY) | - | ||||||||||||
| 451 | if (!proc)
| 0 | ||||||||||||
| 452 | proc = (QFunctionPointer) dlsym(RTLD_DEFAULT, procName); never executed: proc = (QFunctionPointer) dlsym(((void *) 0), procName); | 0 | ||||||||||||
| 453 | #endif | - | ||||||||||||
| 454 | return proc; never executed: return proc; | 0 | ||||||||||||
| 455 | } | - | ||||||||||||
| 456 | - | |||||||||||||
| 457 | QSurfaceFormat QEGLPlatformContext::format() const | - | ||||||||||||
| 458 | { | - | ||||||||||||
| 459 | return m_format; never executed: return m_format; | 0 | ||||||||||||
| 460 | } | - | ||||||||||||
| 461 | - | |||||||||||||
| 462 | EGLContext QEGLPlatformContext::eglContext() const | - | ||||||||||||
| 463 | { | - | ||||||||||||
| 464 | return m_eglContext; never executed: return m_eglContext; | 0 | ||||||||||||
| 465 | } | - | ||||||||||||
| 466 | - | |||||||||||||
| 467 | EGLDisplay QEGLPlatformContext::eglDisplay() const | - | ||||||||||||
| 468 | { | - | ||||||||||||
| 469 | return m_eglDisplay; never executed: return m_eglDisplay; | 0 | ||||||||||||
| 470 | } | - | ||||||||||||
| 471 | - | |||||||||||||
| 472 | EGLConfig QEGLPlatformContext::eglConfig() const | - | ||||||||||||
| 473 | { | - | ||||||||||||
| 474 | return m_eglConfig; never executed: return m_eglConfig; | 0 | ||||||||||||
| 475 | } | - | ||||||||||||
| 476 | - | |||||||||||||
| 477 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |