eglfs: Add support for systems without pbuffer support

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 <louai.al-khanji@digia.com>
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
This commit is contained in:
Laszlo Agocs 2014-09-16 14:12:54 +02:00
parent 881ceeff42
commit 1f040d401d
17 changed files with 288 additions and 30 deletions

View File

@ -606,6 +606,7 @@ bool QOpenGLContext::create()
d->platformGLContext = QGuiApplicationPrivate::platformIntegration()->createPlatformOpenGLContext(this);
if (!d->platformGLContext)
return false;
d->platformGLContext->initialize();
d->platformGLContext->setContext(this);
if (!d->platformGLContext->isSharing())
d->shareContext = 0;

View File

@ -88,6 +88,16 @@ QPlatformOpenGLContext::~QPlatformOpenGLContext()
{
}
/*!
Called after a new instance is constructed. The default implementation does nothing.
Subclasses can use this function to perform additional initialization that relies on
virtual functions.
*/
void QPlatformOpenGLContext::initialize()
{
}
/*!
Reimplement in subclass if your platform uses framebuffer objects for surfaces.

View File

@ -63,6 +63,8 @@ public:
QPlatformOpenGLContext();
virtual ~QPlatformOpenGLContext();
virtual void initialize();
virtual QSurfaceFormat format() const = 0;
virtual void swapBuffers(QPlatformSurface *surface) = 0;

View File

@ -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,6 +238,34 @@ void QEGLPlatformContext::adopt(const QVariant &nativeHandle, QPlatformOpenGLCon
updateFormatFromGL();
}
void QEGLPlatformContext::initialize()
{
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,
EGL_HEIGHT, 1,
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);
return eglCreatePbufferSurface(m_eglDisplay, config, pbufferAttributes);
}
void QEGLPlatformContext::destroyTemporaryOffscreenSurface(EGLSurface surface)
{
eglDestroySurface(m_eglDisplay, surface);
}
void QEGLPlatformContext::updateFormatFromGL()
{
#ifndef QT_NO_OPENGL
@ -250,22 +278,8 @@ void QEGLPlatformContext::updateFormatFromGL()
EGLSurface prevSurfaceDraw = eglGetCurrentSurface(EGL_DRAW);
EGLSurface prevSurfaceRead = eglGetCurrentSurface(EGL_READ);
// Make the context current to ensure the GL version query works. This needs a surface too.
const EGLint pbufferAttributes[] = {
EGL_WIDTH, 1,
EGL_HEIGHT, 1,
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)) {
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
}

View File

@ -59,6 +59,7 @@ public:
EGLConfig *config = 0, const QVariant &nativeHandle = QVariant());
~QEGLPlatformContext();
void initialize();
bool makeCurrent(QPlatformSurface *surface);
void doneCurrent();
void swapBuffers(QPlatformSurface *surface);
@ -74,6 +75,8 @@ public:
protected:
virtual EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) = 0;
virtual EGLSurface createTemporaryOffscreenSurface();
virtual void destroyTemporaryOffscreenSurface(EGLSurface surface);
private:
void init(const QSurfaceFormat &format, QPlatformOpenGLContext *share);

View File

@ -17,13 +17,15 @@ SOURCES += $$PWD/qeglfsintegration.cpp \
$$PWD/qeglfswindow.cpp \
$$PWD/qeglfsscreen.cpp \
$$PWD/qeglfshooks_stub.cpp \
$$PWD/qeglfscontext.cpp
$$PWD/qeglfscontext.cpp \
$$PWD/qeglfsoffscreenwindow.cpp
HEADERS += $$PWD/qeglfsintegration.h \
$$PWD/qeglfswindow.h \
$$PWD/qeglfsscreen.h \
$$PWD/qeglfshooks.h \
$$PWD/qeglfscontext.h
$$PWD/qeglfscontext.h \
$$PWD/qeglfsoffscreenwindow.h
QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF

View File

@ -45,7 +45,8 @@ QT_BEGIN_NAMESPACE
QEglFSContext::QEglFSContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
EGLConfig *config, const QVariant &nativeHandle)
: QEGLPlatformContext(format, share, display, config, nativeHandle)
: QEGLPlatformContext(format, share, display, config, nativeHandle),
m_tempWindow(0)
{
}
@ -57,6 +58,33 @@ EGLSurface QEglFSContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface
return static_cast<QEGLPbuffer *>(surface)->pbuffer();
}
EGLSurface QEglFSContext::createTemporaryOffscreenSurface()
{
if (QEglFSHooks::hooks()->supportsPBuffers())
return QEGLPlatformContext::createTemporaryOffscreenSurface();
if (!m_tempWindow) {
m_tempWindow = QEglFSHooks::hooks()->createNativeOffscreenWindow(format());
if (!m_tempWindow) {
qWarning("QEglFSContext: Failed to create temporary native window");
return EGL_NO_SURFACE;
}
}
EGLConfig config = q_configFromGLFormat(eglDisplay(), format());
return eglCreateWindowSurface(eglDisplay(), config, m_tempWindow, 0);
}
void QEglFSContext::destroyTemporaryOffscreenSurface(EGLSurface surface)
{
if (QEglFSHooks::hooks()->supportsPBuffers()) {
QEGLPlatformContext::destroyTemporaryOffscreenSurface(surface);
} else {
eglDestroySurface(eglDisplay(), surface);
QEglFSHooks::hooks()->destroyNativeWindow(m_tempWindow);
m_tempWindow = 0;
}
}
void QEglFSContext::swapBuffers(QPlatformSurface *surface)
{
// draw the cursor

View File

@ -45,7 +45,12 @@ public:
QEglFSContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
EGLConfig *config, const QVariant &nativeHandle);
EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) Q_DECL_OVERRIDE;
EGLSurface createTemporaryOffscreenSurface() Q_DECL_OVERRIDE;
void destroyTemporaryOffscreenSurface(EGLSurface surface) Q_DECL_OVERRIDE;
void swapBuffers(QPlatformSurface *surface) Q_DECL_OVERRIDE;
private:
EGLNativeWindowType m_tempWindow;
};
QT_END_NAMESPACE

View File

@ -62,6 +62,7 @@ public:
virtual EGLNativeWindowType createNativeWindow(QPlatformWindow *platformWindow,
const QSize &size,
const QSurfaceFormat &format);
virtual EGLNativeWindowType createNativeOffscreenWindow(const QSurfaceFormat &format);
virtual void destroyNativeWindow(EGLNativeWindowType window);
virtual bool hasCapability(QPlatformIntegration::Capability cap) const;
virtual QPlatformCursor *createCursor(QPlatformScreen *screen) const;
@ -72,6 +73,8 @@ public:
virtual QByteArray fbDeviceName() const;
virtual int framebufferIndex() const;
virtual bool supportsPBuffers() const;
static QEglFSHooks *hooks()
{
#ifdef EGLFS_PLATFORM_HOOKS

View File

@ -108,10 +108,12 @@ public:
EGLNativeWindowType createNativeWindow(QPlatformWindow *platformWindow,
const QSize &size,
const QSurfaceFormat &format) Q_DECL_OVERRIDE;
EGLNativeWindowType createNativeOffscreenWindow(const QSurfaceFormat &format) Q_DECL_OVERRIDE;
void destroyNativeWindow(EGLNativeWindowType window) Q_DECL_OVERRIDE;
bool hasCapability(QPlatformIntegration::Capability cap) const Q_DECL_OVERRIDE;
QPlatformCursor *createCursor(QPlatformScreen *screen) const Q_DECL_OVERRIDE;
void presentBuffer() Q_DECL_OVERRIDE;
bool supportsPBuffers() const Q_DECL_OVERRIDE;
private:
bool setup_kms();
@ -259,6 +261,18 @@ EGLNativeWindowType QEglKmsHooks::createNativeWindow(QPlatformWindow *platformWi
return reinterpret_cast<EGLNativeWindowType>(m_gbm_surface);
}
EGLNativeWindowType QEglKmsHooks::createNativeOffscreenWindow(const QSurfaceFormat &format)
{
Q_UNUSED(format);
gbm_surface *surface = gbm_surface_create(m_gbm_device,
1, 1,
GBM_FORMAT_XRGB8888,
GBM_BO_USE_RENDERING);
return reinterpret_cast<EGLNativeWindowType>(surface);
}
void QEglKmsHooks::destroyNativeWindow(EGLNativeWindowType window)
{
gbm_surface *surface = reinterpret_cast<gbm_surface *>(window);
@ -413,6 +427,11 @@ void QEglKmsHooks::presentBuffer()
}
}
bool QEglKmsHooks::supportsPBuffers() const
{
return false;
}
bool QEglKmsHooks::setup_kms()
{
drmModeRes *resources;

View File

@ -162,6 +162,12 @@ EGLNativeWindowType QEglFSHooks::createNativeWindow(QPlatformWindow *platformWin
return 0;
}
EGLNativeWindowType QEglFSHooks::createNativeOffscreenWindow(const QSurfaceFormat &format)
{
Q_UNUSED(format);
return 0;
}
void QEglFSHooks::destroyNativeWindow(EGLNativeWindowType window)
{
Q_UNUSED(window);
@ -194,6 +200,11 @@ void QEglFSHooks::presentBuffer()
{
}
bool QEglFSHooks::supportsPBuffers() const
{
return true;
}
#ifndef EGLFS_PLATFORM_HOOKS
QEglFSHooks stubHooks;
#endif

View File

@ -36,6 +36,7 @@
#include "qeglfswindow.h"
#include "qeglfshooks.h"
#include "qeglfscontext.h"
#include "qeglfsoffscreenwindow.h"
#include <QtGui/private/qguiapplication_p.h>
@ -116,9 +117,9 @@ QEGLPlatformContext *QEglFSIntegration::createContext(const QSurfaceFormat &form
QSurfaceFormat adjustedFormat = QEglFSHooks::hooks()->surfaceFormatFor(format);
if (!nativeHandle || nativeHandle->isNull()) {
EGLConfig config = QEglFSIntegration::chooseConfig(display, adjustedFormat);
ctx = new QEglFSContext(adjustedFormat, shareContext, display, &config, QVariant());
ctx = new QEglFSContext(adjustedFormat, shareContext, display, &config, QVariant());
} else {
ctx = new QEglFSContext(adjustedFormat, shareContext, display, 0, *nativeHandle);
ctx = new QEglFSContext(adjustedFormat, shareContext, display, 0, *nativeHandle);
}
*nativeHandle = QVariant::fromValue<QEGLNativeContext>(QEGLNativeContext(ctx->eglContext(), display));
return ctx;
@ -128,7 +129,13 @@ QPlatformOffscreenSurface *QEglFSIntegration::createOffscreenSurface(EGLDisplay
const QSurfaceFormat &format,
QOffscreenSurface *surface) const
{
return new QEGLPbuffer(display, QEglFSHooks::hooks()->surfaceFormatFor(format), surface);
QSurfaceFormat fmt = QEglFSHooks::hooks()->surfaceFormatFor(format);
if (QEglFSHooks::hooks()->supportsPBuffers())
return new QEGLPbuffer(display, fmt, surface);
else
return new QEglFSOffscreenWindow(display, fmt, surface);
// Never return null. Multiple QWindows are not supported by this plugin.
}
QVariant QEglFSIntegration::styleHint(QPlatformIntegration::StyleHint hint) const

View File

@ -0,0 +1,85 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qeglfsoffscreenwindow.h"
#include "qeglfshooks.h"
#include <QtGui/QOffscreenSurface>
#include <QtPlatformSupport/private/qeglconvenience_p.h>
QT_BEGIN_NAMESPACE
/*
In some cases pbuffers are not available. Triggering QtGui's built-in
fallback for a hidden QWindow is not suitable for eglfs since this would be
treated as an attempt to create multiple top-level, native windows.
Therefore this class is provided as an alternative to QEGLPbuffer.
This class requires the hooks to implement createNativeOffscreenWindow().
*/
QEglFSOffscreenWindow::QEglFSOffscreenWindow(EGLDisplay display, const QSurfaceFormat &format, QOffscreenSurface *offscreenSurface)
: QPlatformOffscreenSurface(offscreenSurface)
, m_format(format)
, m_display(display)
, m_surface(EGL_NO_SURFACE)
, m_window(0)
{
m_window = QEglFSHooks::hooks()->createNativeOffscreenWindow(format);
if (!m_window) {
qWarning("QEglFSOffscreenWindow: Failed to create native window");
return;
}
EGLConfig config = q_configFromGLFormat(m_display, m_format);
m_surface = eglCreateWindowSurface(m_display, config, m_window, 0);
if (m_surface != EGL_NO_SURFACE)
m_format = q_glFormatFromConfig(m_display, config);
}
QEglFSOffscreenWindow::~QEglFSOffscreenWindow()
{
if (m_surface != EGL_NO_SURFACE)
eglDestroySurface(m_display, m_surface);
if (m_window)
QEglFSHooks::hooks()->destroyNativeWindow(m_window);
}
QT_END_NAMESPACE

View File

@ -0,0 +1,68 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QEGLFSOFFSCREENWINDOW_H
#define QEGLFSOFFSCREENWINDOW_H
#include <EGL/egl.h>
#include <qpa/qplatformoffscreensurface.h>
QT_BEGIN_NAMESPACE
class QEglFSOffscreenWindow : public QPlatformOffscreenSurface
{
public:
QEglFSOffscreenWindow(EGLDisplay display, const QSurfaceFormat &format, QOffscreenSurface *offscreenSurface);
~QEglFSOffscreenWindow();
QSurfaceFormat format() const Q_DECL_OVERRIDE { return m_format; }
bool isValid() const Q_DECL_OVERRIDE { return m_surface != EGL_NO_SURFACE; }
private:
QSurfaceFormat m_format;
EGLDisplay m_display;
EGLSurface m_surface;
EGLNativeWindowType m_window;
};
QT_END_NAMESPACE
#endif // QEGLFSOFFSCREENWINDOW_H

View File

@ -164,7 +164,7 @@ EGLenum QQnxGLContext::checkEGLError(const char *msg)
return error;
}
void QQnxGLContext::initialize()
void QQnxGLContext::initializeContext()
{
qGLContextDebug() << Q_FUNC_INFO;
@ -182,7 +182,7 @@ void QQnxGLContext::initialize()
}
}
void QQnxGLContext::shutdown()
void QQnxGLContext::shutdownContext()
{
qGLContextDebug() << Q_FUNC_INFO;

View File

@ -53,8 +53,8 @@ public:
static EGLenum checkEGLError(const char *msg);
static void initialize();
static void shutdown();
static void initializeContext();
static void shutdownContext();
void requestSurfaceChange();

View File

@ -182,7 +182,7 @@ QQnxIntegration::QQnxIntegration(const QStringList &paramList)
#if !defined(QT_NO_OPENGL)
// Initialize global OpenGL resources
QQnxGLContext::initialize();
QQnxGLContext::initializeContext();
#endif
// Create/start event thread
@ -306,7 +306,7 @@ QQnxIntegration::~QQnxIntegration()
#if !defined(QT_NO_OPENGL)
// Cleanup global OpenGL resources
QQnxGLContext::shutdown();
QQnxGLContext::shutdownContext();
#endif
#if defined(QQNX_PPS)