From 1f040d401d322cec9dc56c93e78899a429cb6e5a Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 16 Sep 2014 14:12:54 +0200 Subject: eglfs: Add support for systems without pbuffer support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a small native window and window surface in case the hooks indicate that pbuffer support is not available. Change-Id: I6515309041f0e1e2f5321d59941f35d6ee16dca7 Reviewed-by: Louai Al-Khanji Reviewed-by: Jørgen Lind --- .../eglconvenience/qeglplatformcontext.cpp | 46 ++++++++++++++-------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'src/platformsupport/eglconvenience/qeglplatformcontext.cpp') diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp index 1a1e298935..07ef202195 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp +++ b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp @@ -187,7 +187,7 @@ void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLCont q_printEglConfig(m_eglDisplay, m_eglConfig); } - updateFormatFromGL(); + // Cannot just call updateFormatFromGL() since it relies on virtuals. Defer it to initialize(). } void QEGLPlatformContext::adopt(const QVariant &nativeHandle, QPlatformOpenGLContext *share) @@ -238,18 +238,13 @@ void QEGLPlatformContext::adopt(const QVariant &nativeHandle, QPlatformOpenGLCon updateFormatFromGL(); } -void QEGLPlatformContext::updateFormatFromGL() +void QEGLPlatformContext::initialize() { -#ifndef QT_NO_OPENGL - // Have to save & restore to prevent QOpenGLContext::currentContext() from becoming - // inconsistent after QOpenGLContext::create(). - EGLDisplay prevDisplay = eglGetCurrentDisplay(); - if (prevDisplay == EGL_NO_DISPLAY) // when no context is current - prevDisplay = m_eglDisplay; - EGLContext prevContext = eglGetCurrentContext(); - EGLSurface prevSurfaceDraw = eglGetCurrentSurface(EGL_DRAW); - EGLSurface prevSurfaceRead = eglGetCurrentSurface(EGL_READ); + updateFormatFromGL(); +} +EGLSurface QEGLPlatformContext::createTemporaryOffscreenSurface() +{ // Make the context current to ensure the GL version query works. This needs a surface too. const EGLint pbufferAttributes[] = { EGL_WIDTH, 1, @@ -257,15 +252,34 @@ void QEGLPlatformContext::updateFormatFromGL() EGL_LARGEST_PBUFFER, EGL_FALSE, EGL_NONE }; + // Cannot just pass m_eglConfig because it may not be suitable for pbuffers. Instead, // do what QEGLPbuffer would do: request a config with the same attributes but with // PBUFFER_BIT set. EGLConfig config = q_configFromGLFormat(m_eglDisplay, m_format, false, EGL_PBUFFER_BIT); - EGLSurface pbuffer = eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes); - if (pbuffer == EGL_NO_SURFACE) - return; - if (eglMakeCurrent(m_eglDisplay, pbuffer, pbuffer, m_eglContext)) { + return eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes); +} + +void QEGLPlatformContext::destroyTemporaryOffscreenSurface(EGLSurface surface) +{ + eglDestroySurface(m_eglDisplay, surface); +} + +void QEGLPlatformContext::updateFormatFromGL() +{ +#ifndef QT_NO_OPENGL + // Have to save & restore to prevent QOpenGLContext::currentContext() from becoming + // inconsistent after QOpenGLContext::create(). + EGLDisplay prevDisplay = eglGetCurrentDisplay(); + if (prevDisplay == EGL_NO_DISPLAY) // when no context is current + prevDisplay = m_eglDisplay; + EGLContext prevContext = eglGetCurrentContext(); + EGLSurface prevSurfaceDraw = eglGetCurrentSurface(EGL_DRAW); + EGLSurface prevSurfaceRead = eglGetCurrentSurface(EGL_READ); + + EGLSurface tempSurface = createTemporaryOffscreenSurface(); + if (eglMakeCurrent(m_eglDisplay, tempSurface, tempSurface, m_eglContext)) { if (m_format.renderableType() == QSurfaceFormat::OpenGL || m_format.renderableType() == QSurfaceFormat::OpenGLES) { const GLubyte *s = glGetString(GL_VERSION); @@ -303,7 +317,7 @@ void QEGLPlatformContext::updateFormatFromGL() } eglMakeCurrent(prevDisplay, prevSurfaceDraw, prevSurfaceRead, prevContext); } - eglDestroySurface(m_eglDisplay, pbuffer); + destroyTemporaryOffscreenSurface(tempSurface); #endif // QT_NO_OPENGL } -- cgit v1.2.3