diff options
author | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2013-03-20 13:46:57 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2013-03-20 13:49:28 +0100 |
commit | 76c0be34cd4ff4564693162fa7528463e23ce9d8 (patch) | |
tree | f165b7bc319548fb0082365411a871028f92e89e /src/platformsupport/eglconvenience | |
parent | 27b4fe96b59e9e63d1e570e802c072e9afdfb2d4 (diff) | |
parent | 36cb3f3f655a9090c82de609010cbfb88651a0f3 (diff) |
Merge branch 'dev' into stable
This starts Qt 5.1 release cycle
Conflicts:
src/gui/text/qfontdatabase.cpp
src/gui/text/qharfbuzz_copy_p.h
src/widgets/kernel/qapplication.cpp
src/widgets/kernel/qcoreapplication.cpp
Change-Id: I72fbf83ab3c2206aeea1b089428b0fc2a89bd62b
Diffstat (limited to 'src/platformsupport/eglconvenience')
7 files changed, 278 insertions, 47 deletions
diff --git a/src/platformsupport/eglconvenience/eglconvenience.pri b/src/platformsupport/eglconvenience/eglconvenience.pri index 3257bcb8d2..506f4ab4ea 100644 --- a/src/platformsupport/eglconvenience/eglconvenience.pri +++ b/src/platformsupport/eglconvenience/eglconvenience.pri @@ -1,10 +1,12 @@ contains(QT_CONFIG,egl) { HEADERS += \ $$PWD/qeglconvenience_p.h \ - $$PWD/qeglplatformcontext_p.h + $$PWD/qeglplatformcontext_p.h \ + $$PWD/qeglpbuffer_p.h SOURCES += \ $$PWD/qeglconvenience.cpp \ - $$PWD/qeglplatformcontext.cpp + $$PWD/qeglplatformcontext.cpp \ + $$PWD/qeglpbuffer.cpp contains(QT_CONFIG,xlib) { HEADERS += \ diff --git a/src/platformsupport/eglconvenience/qeglconvenience.cpp b/src/platformsupport/eglconvenience/qeglconvenience.cpp index 0f40a2e34b..b711a2aebd 100644 --- a/src/platformsupport/eglconvenience/qeglconvenience.cpp +++ b/src/platformsupport/eglconvenience/qeglconvenience.cpp @@ -210,75 +210,106 @@ bool q_reduceConfigAttributes(QVector<EGLint> *configAttributes) return false; } -EGLConfig q_configFromGLFormat(EGLDisplay display, const QSurfaceFormat &format, bool highestPixelFormat, int surfaceType) +QEglConfigChooser::QEglConfigChooser(EGLDisplay display) + : m_display(display) + , m_surfaceType(EGL_WINDOW_BIT) + , m_ignore(false) + , m_confAttrRed(0) + , m_confAttrGreen(0) + , m_confAttrBlue(0) + , m_confAttrAlpha(0) { - EGLConfig cfg = 0; - QVector<EGLint> configureAttributes = q_createConfigAttributesFromFormat(format); +} + +QEglConfigChooser::~QEglConfigChooser() +{ +} + +EGLConfig QEglConfigChooser::chooseConfig() +{ + QVector<EGLint> configureAttributes = q_createConfigAttributesFromFormat(m_format); configureAttributes.append(EGL_SURFACE_TYPE); - configureAttributes.append(surfaceType); + configureAttributes.append(surfaceType()); configureAttributes.append(EGL_RENDERABLE_TYPE); - if (format.renderableType() == QSurfaceFormat::OpenVG) + if (m_format.renderableType() == QSurfaceFormat::OpenVG) configureAttributes.append(EGL_OPENVG_BIT); #ifdef EGL_VERSION_1_4 - else if (format.renderableType() == QSurfaceFormat::OpenGL) + else if (m_format.renderableType() == QSurfaceFormat::OpenGL) configureAttributes.append(EGL_OPENGL_BIT); #endif - else if (format.majorVersion() == 1) + else if (m_format.majorVersion() == 1) configureAttributes.append(EGL_OPENGL_ES_BIT); else configureAttributes.append(EGL_OPENGL_ES2_BIT); configureAttributes.append(EGL_NONE); + EGLConfig cfg = 0; do { // Get the number of matching configurations for this set of properties. EGLint matching = 0; - if (!eglChooseConfig(display, configureAttributes.constData(), 0, 0, &matching) || !matching) + if (!eglChooseConfig(display(), configureAttributes.constData(), 0, 0, &matching) || !matching) continue; - // If we want the best pixel format, then return the first - // matching configuration. - if (highestPixelFormat) { - eglChooseConfig(display, configureAttributes.constData(), &cfg, 1, &matching); - if (matching < 1) - continue; - return cfg; - } - // Fetch all of the matching configurations and find the // first that matches the pixel format we wanted. int i = configureAttributes.indexOf(EGL_RED_SIZE); - int confAttrRed = configureAttributes.at(i+1); + m_confAttrRed = configureAttributes.at(i+1); i = configureAttributes.indexOf(EGL_GREEN_SIZE); - int confAttrGreen = configureAttributes.at(i+1); + m_confAttrGreen = configureAttributes.at(i+1); i = configureAttributes.indexOf(EGL_BLUE_SIZE); - int confAttrBlue = configureAttributes.at(i+1); + m_confAttrBlue = configureAttributes.at(i+1); i = configureAttributes.indexOf(EGL_ALPHA_SIZE); - int confAttrAlpha = i == -1 ? 0 : configureAttributes.at(i+1); - - EGLint size = matching; - EGLConfig *configs = new EGLConfig [size]; - eglChooseConfig(display, configureAttributes.constData(), configs, size, &matching); - for (EGLint index = 0; index < size; ++index) { - EGLint red, green, blue, alpha; - eglGetConfigAttrib(display, configs[index], EGL_RED_SIZE, &red); - eglGetConfigAttrib(display, configs[index], EGL_GREEN_SIZE, &green); - eglGetConfigAttrib(display, configs[index], EGL_BLUE_SIZE, &blue); - eglGetConfigAttrib(display, configs[index], EGL_ALPHA_SIZE, &alpha); - if ((confAttrRed == 0 || red == confAttrRed) && - (confAttrGreen == 0 || green == confAttrGreen) && - (confAttrBlue == 0 || blue == confAttrBlue) && - (confAttrAlpha == 0 || alpha == confAttrAlpha)) { - cfg = configs[index]; - delete [] configs; - return cfg; - } + m_confAttrAlpha = i == -1 ? 0 : configureAttributes.at(i+1); + + QVector<EGLConfig> configs(matching); + eglChooseConfig(display(), configureAttributes.constData(), configs.data(), configs.size(), &matching); + if (!cfg && matching > 0) + cfg = configs.first(); + + for (int i = 0; i < configs.size(); ++i) { + if (filterConfig(configs[i])) + return configs.at(i); } - delete [] configs; } while (q_reduceConfigAttributes(&configureAttributes)); - qWarning("Cant find EGLConfig, returning null config"); - return 0; + + if (!cfg) + qWarning("Cant find EGLConfig, returning null config"); + return cfg; +} + +bool QEglConfigChooser::filterConfig(EGLConfig config) const +{ + if (m_ignore) + return true; + + EGLint red = 0; + EGLint green = 0; + EGLint blue = 0; + EGLint alpha = 0; + + if (m_confAttrRed) + eglGetConfigAttrib(display(), config, EGL_RED_SIZE, &red); + if (m_confAttrGreen) + eglGetConfigAttrib(display(), config, EGL_GREEN_SIZE, &green); + if (m_confAttrBlue) + eglGetConfigAttrib(display(), config, EGL_BLUE_SIZE, &blue); + if (m_confAttrAlpha) + eglGetConfigAttrib(display(), config, EGL_ALPHA_SIZE, &alpha); + + return red == m_confAttrRed && green == m_confAttrGreen + && blue == m_confAttrBlue && alpha == m_confAttrAlpha; +} + +EGLConfig q_configFromGLFormat(EGLDisplay display, const QSurfaceFormat &format, bool highestPixelFormat, int surfaceType) +{ + QEglConfigChooser chooser(display); + chooser.setSurfaceFormat(format); + chooser.setSurfaceType(surfaceType); + chooser.setIgnoreColorChannels(highestPixelFormat); + + return chooser.chooseConfig(); } QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, const QSurfaceFormat &referenceFormat) diff --git a/src/platformsupport/eglconvenience/qeglconvenience_p.h b/src/platformsupport/eglconvenience/qeglconvenience_p.h index 1e5cbafa61..35c225cc2f 100644 --- a/src/platformsupport/eglconvenience/qeglconvenience_p.h +++ b/src/platformsupport/eglconvenience/qeglconvenience_p.h @@ -56,6 +56,41 @@ QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, bool q_hasEglExtension(EGLDisplay display,const char* extensionName); void q_printEglConfig(EGLDisplay display, EGLConfig config); +class QEglConfigChooser +{ +public: + QEglConfigChooser(EGLDisplay display); + virtual ~QEglConfigChooser(); + + EGLDisplay display() const { return m_display; } + + void setSurfaceType(EGLint surfaceType) { m_surfaceType = surfaceType; } + EGLint surfaceType() const { return m_surfaceType; } + + void setSurfaceFormat(const QSurfaceFormat &format) { m_format = format; } + QSurfaceFormat surfaceFormat() const { return m_format; } + + void setIgnoreColorChannels(bool ignore) { m_ignore = ignore; } + bool ignoreColorChannels() const { return m_ignore; } + + EGLConfig chooseConfig(); + +protected: + virtual bool filterConfig(EGLConfig config) const; + +private: + QSurfaceFormat m_format; + EGLDisplay m_display; + EGLint m_surfaceType; + bool m_ignore; + + int m_confAttrRed; + int m_confAttrGreen; + int m_confAttrBlue; + int m_confAttrAlpha; +}; + + QT_END_NAMESPACE #endif //QEGLCONVENIENCE_H diff --git a/src/platformsupport/eglconvenience/qeglpbuffer.cpp b/src/platformsupport/eglconvenience/qeglpbuffer.cpp new file mode 100644 index 0000000000..919314e9aa --- /dev/null +++ b/src/platformsupport/eglconvenience/qeglpbuffer.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 <QtGui/QOffscreenSurface> +#include "qeglpbuffer_p.h" +#include "qeglconvenience_p.h" + +QT_BEGIN_NAMESPACE + +QEGLPbuffer::QEGLPbuffer(EGLDisplay display, const QSurfaceFormat &format, QOffscreenSurface *offscreenSurface) + : QPlatformOffscreenSurface(offscreenSurface) + , m_format(format) + , m_display(display) + , m_pbuffer(EGL_NO_SURFACE) +{ + EGLConfig config = q_configFromGLFormat(m_display, m_format, false, EGL_PBUFFER_BIT); + + if (config) { + const EGLint attributes[] = { + EGL_WIDTH, offscreenSurface->size().width(), + EGL_HEIGHT, offscreenSurface->size().height(), + EGL_LARGEST_PBUFFER, EGL_FALSE, + EGL_NONE + }; + + m_pbuffer = eglCreatePbufferSurface(m_display, config, attributes); + + if (m_pbuffer != EGL_NO_SURFACE) + m_format = q_glFormatFromConfig(m_display, config); + } +} + +QEGLPbuffer::~QEGLPbuffer() +{ + eglDestroySurface(m_display, m_pbuffer); +} + +QT_END_NAMESPACE diff --git a/src/platformsupport/eglconvenience/qeglpbuffer_p.h b/src/platformsupport/eglconvenience/qeglpbuffer_p.h new file mode 100644 index 0000000000..1b4ac6f991 --- /dev/null +++ b/src/platformsupport/eglconvenience/qeglpbuffer_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 QEGLPBUFFER_H +#define QEGLPBUFFER_H + +#include <EGL/egl.h> +#include <qpa/qplatformoffscreensurface.h> + +QT_BEGIN_NAMESPACE + +class QEGLPbuffer : public QPlatformOffscreenSurface +{ +public: + QEGLPbuffer(EGLDisplay display, const QSurfaceFormat &format, QOffscreenSurface *offscreenSurface); + ~QEGLPbuffer(); + + QSurfaceFormat format() const { return m_format; } + bool isValid() const { return m_pbuffer != EGL_NO_SURFACE; } + + EGLSurface pbuffer() const { return m_pbuffer; } + +private: + QSurfaceFormat m_format; + EGLDisplay m_display; + EGLSurface m_pbuffer; +}; + +QT_END_NAMESPACE + +#endif // QEGLPBUFFER_H diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp index 7cce8d89d5..8152f74067 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp +++ b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp @@ -63,9 +63,23 @@ QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatform EGLenum eglApi) : m_eglDisplay(display) , m_eglApi(eglApi) - , m_eglConfig(q_configFromGLFormat(display, format, true)) - , m_format(q_glFormatFromConfig(display, m_eglConfig)) + , m_eglConfig(q_configFromGLFormat(display, format)) { + init(format, share); +} + +QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, + EGLConfig config, EGLenum eglApi) + : m_eglDisplay(display) + , m_eglApi(eglApi) + , m_eglConfig(config) +{ + init(format, share); +} + +void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLContext *share) +{ + m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig); m_shareContext = share ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0; QVector<EGLint> contextAttrs; diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h index 76002da2df..952f5a856a 100644 --- a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h +++ b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h @@ -51,6 +51,8 @@ class QEGLPlatformContext : public QPlatformOpenGLContext public: QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, EGLenum eglApi = EGL_OPENGL_ES_API); + QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display, + EGLConfig config, EGLenum eglApi = EGL_OPENGL_ES_API); ~QEGLPlatformContext(); bool makeCurrent(QPlatformSurface *surface); @@ -70,12 +72,14 @@ protected: virtual EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) = 0; private: + void init(const QSurfaceFormat &format, QPlatformOpenGLContext *share); + EGLContext m_eglContext; EGLContext m_shareContext; EGLDisplay m_eglDisplay; EGLenum m_eglApi; EGLConfig m_eglConfig; - const QSurfaceFormat m_format; + QSurfaceFormat m_format; }; #endif //QEGLPLATFORMCONTEXT_H |