From 9ca3f9c6b6ae50c6b8a19d5e4b26bff15d5421e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 23 Mar 2011 07:01:56 +0100 Subject: Lighthouse: Wayland, implement gl_integration --- .../platforms/eglconvenience/qeglconvenience.h | 4 - .../wayland/gl_integration/gl_integration.pri | 13 ++ .../gl_integration/qwaylandglintegration.cpp | 11 ++ .../wayland/gl_integration/qwaylandglintegration.h | 20 +++ .../gl_integration/qwaylandglwindowsurface.cpp | 181 ++++++++++++++++++++ .../gl_integration/qwaylandglwindowsurface.h | 69 ++++++++ .../wayland_egl/qwaylandeglinclude.h | 16 ++ .../wayland_egl/qwaylandeglintegration.cpp | 48 ++++++ .../wayland_egl/qwaylandeglintegration.h | 32 ++++ .../wayland_egl/qwaylandeglwindow.cpp | 112 +++++++++++++ .../gl_integration/wayland_egl/qwaylandeglwindow.h | 71 ++++++++ .../wayland_egl/qwaylandglcontext.cpp | 155 +++++++++++++++++ .../gl_integration/wayland_egl/qwaylandglcontext.h | 81 +++++++++ .../gl_integration/wayland_egl/wayland_egl.pri | 12 ++ src/plugins/platforms/wayland/qwaylanddisplay.cpp | 30 ++-- src/plugins/platforms/wayland/qwaylanddisplay.h | 17 +- .../platforms/wayland/qwaylanddrmsurface.cpp | 183 --------------------- src/plugins/platforms/wayland/qwaylanddrmsurface.h | 70 -------- .../platforms/wayland/qwaylandeglwindow.cpp | 113 ------------- src/plugins/platforms/wayland/qwaylandeglwindow.h | 68 -------- .../platforms/wayland/qwaylandglcontext.cpp | 155 ----------------- src/plugins/platforms/wayland/qwaylandglcontext.h | 81 --------- src/plugins/platforms/wayland/qwaylandinclude.h | 63 ------- .../platforms/wayland/qwaylandintegration.cpp | 14 +- src/plugins/platforms/wayland/qwaylandwindow.h | 1 - src/plugins/platforms/wayland/wayland.pro | 18 +- 26 files changed, 852 insertions(+), 786 deletions(-) create mode 100644 src/plugins/platforms/wayland/gl_integration/gl_integration.pri create mode 100644 src/plugins/platforms/wayland/gl_integration/qwaylandglintegration.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/qwaylandglintegration.h create mode 100644 src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.h create mode 100644 src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglinclude.h create mode 100644 src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.h create mode 100644 src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h create mode 100644 src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.h create mode 100644 src/plugins/platforms/wayland/gl_integration/wayland_egl/wayland_egl.pri delete mode 100644 src/plugins/platforms/wayland/qwaylanddrmsurface.cpp delete mode 100644 src/plugins/platforms/wayland/qwaylanddrmsurface.h delete mode 100644 src/plugins/platforms/wayland/qwaylandeglwindow.cpp delete mode 100644 src/plugins/platforms/wayland/qwaylandeglwindow.h delete mode 100644 src/plugins/platforms/wayland/qwaylandglcontext.cpp delete mode 100644 src/plugins/platforms/wayland/qwaylandglcontext.h delete mode 100644 src/plugins/platforms/wayland/qwaylandinclude.h diff --git a/src/plugins/platforms/eglconvenience/qeglconvenience.h b/src/plugins/platforms/eglconvenience/qeglconvenience.h index 8668095..fab1cb0 100644 --- a/src/plugins/platforms/eglconvenience/qeglconvenience.h +++ b/src/plugins/platforms/eglconvenience/qeglconvenience.h @@ -46,11 +46,7 @@ #include #include -#ifdef Q_PLATFORM_WAYLAND -#include "qwaylandinclude.h" -#else #include -#endif QT_BEGIN_NAMESPACE QVector q_createConfigAttributesFromFormat(const QPlatformWindowFormat &format); diff --git a/src/plugins/platforms/wayland/gl_integration/gl_integration.pri b/src/plugins/platforms/wayland/gl_integration/gl_integration.pri new file mode 100644 index 0000000..8a792a5 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/gl_integration.pri @@ -0,0 +1,13 @@ +HEADERS += \ + $$PWD/qwaylandglintegration.h \ + $$PWD/qwaylandglwindowsurface.h + +SOURCES += \ + $$PWD/qwaylandglintegration.cpp \ + $$PWD/qwaylandglwindowsurface.cpp + +wayland_egl { + include ($$PWD/wayland_egl/wayland_egl.pri) +} + + diff --git a/src/plugins/platforms/wayland/gl_integration/qwaylandglintegration.cpp b/src/plugins/platforms/wayland/gl_integration/qwaylandglintegration.cpp new file mode 100644 index 0000000..9a0a824 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/qwaylandglintegration.cpp @@ -0,0 +1,11 @@ +#include "qwaylandglintegration.h" + +QWaylandGLIntegration::QWaylandGLIntegration() +{ + +} + +QWaylandGLIntegration::~QWaylandGLIntegration() +{ + +} diff --git a/src/plugins/platforms/wayland/gl_integration/qwaylandglintegration.h b/src/plugins/platforms/wayland/gl_integration/qwaylandglintegration.h new file mode 100644 index 0000000..a1f6b2c --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/qwaylandglintegration.h @@ -0,0 +1,20 @@ +#ifndef QWAYLANDGLINTEGRATION_H +#define QWAYLANDGLINTEGRATION_H + +class QWaylandWindow; +class QWidget; + +class QWaylandGLIntegration +{ +public: + QWaylandGLIntegration(); + virtual ~QWaylandGLIntegration(); + + virtual void initialize() = 0; + + virtual QWaylandWindow *createEglWindow(QWidget *widget) = 0; + + static QWaylandGLIntegration *createEglIntegration(struct wl_display *waylandDisplay); +}; + +#endif // QWAYLANDGLINTEGRATION_H diff --git a/src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.cpp b/src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.cpp new file mode 100644 index 0000000..ca9fb97 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.cpp @@ -0,0 +1,181 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandglwindowsurface.h" + +#include "qwaylanddisplay.h" +#include "qwaylandwindow.h" +#include "qwaylandscreen.h" + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &br) +{ + const GLenum target = GL_TEXTURE_2D; + QRectF src = br.isEmpty() + ? QRectF(QPointF(), texSize) + : QRectF(QPointF(br.x(), texSize.height() - br.bottom()), br.size()); + + if (target == GL_TEXTURE_2D) { + qreal width = texSize.width(); + qreal height = texSize.height(); + + src.setLeft(src.left() / width); + src.setRight(src.right() / width); + src.setTop(src.top() / height); + src.setBottom(src.bottom() / height); + } + + const GLfloat tx1 = src.left(); + const GLfloat tx2 = src.right(); + const GLfloat ty1 = src.top(); + const GLfloat ty2 = src.bottom(); + + GLfloat texCoordArray[4*2] = { + tx1, ty2, tx2, ty2, tx2, ty1, tx1, ty1 + }; + + GLfloat vertexArray[4*2]; + vertexArray[0] = rect.left(); vertexArray[1] = rect.top(); + vertexArray[2] = rect.right(); vertexArray[3] = rect.top(); + vertexArray[4] = rect.right(); vertexArray[5] = rect.bottom(); + vertexArray[6] = rect.left(); vertexArray[7] = rect.bottom(); + + glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexArray); + glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, texCoordArray); + + glBindTexture(target, tex_id); + + glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR); + glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR); + glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); + + glBindTexture(target, 0); +} + +static void blitTexture(QGLContext *ctx, GLuint texture, const QSize &viewport, const QSize &texSize, const QRect &targetRect, const QRect &sourceRect) +{ + glDisable(GL_DEPTH_TEST); + glDisable(GL_SCISSOR_TEST); + glDisable(GL_BLEND); + glViewport(0, 0, viewport.width(), viewport.height()); + + QGLShaderProgram *blitProgram = + QGLEngineSharedShaders::shadersForContext(ctx)->blitProgram(); + blitProgram->bind(); + blitProgram->setUniformValue("imageTexture", 0 /*QT_IMAGE_TEXTURE_UNIT*/); + + // The shader manager's blit program does not multiply the + // vertices by the pmv matrix, so we need to do the effect + // of the orthographic projection here ourselves. + QRectF r; + qreal w = viewport.width(); + qreal h = viewport.height(); + r.setLeft((targetRect.left() / w) * 2.0f - 1.0f); + if (targetRect.right() == (viewport.width() - 1)) + r.setRight(1.0f); + else + r.setRight((targetRect.right() / w) * 2.0f - 1.0f); + r.setBottom((targetRect.top() / h) * 2.0f - 1.0f); + if (targetRect.bottom() == (viewport.height() - 1)) + r.setTop(1.0f); + else + r.setTop((targetRect.bottom() / w) * 2.0f - 1.0f); + + drawTexture(r, texture, texSize, sourceRect); +} + +QWaylandGLWindowSurface::QWaylandGLWindowSurface(QWidget *window) + : QWindowSurface(window) + , mDisplay(QWaylandScreen::waylandScreenFromWidget(window)->display()) + , mPaintDevice(0) +{ + +} + +QWaylandGLWindowSurface::~QWaylandGLWindowSurface() +{ + delete mPaintDevice; +} + +QPaintDevice *QWaylandGLWindowSurface::paintDevice() +{ + return mPaintDevice; +} + +void QWaylandGLWindowSurface::beginPaint(const QRegion &) +{ + window()->platformWindow()->glContext()->makeCurrent(); + glClearColor(0,0,0,0xff); + glClear(GL_COLOR_BUFFER_BIT); +} + +void QWaylandGLWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(offset); + Q_UNUSED(region); + QWaylandWindow *ww = (QWaylandWindow *) widget->platformWindow(); + + if (mPaintDevice->isBound()) + mPaintDevice->release(); + + QRect rect(0,0,size().width(),size().height()); + QGLContext *ctx = QGLContext::fromPlatformGLContext(ww->glContext()); + blitTexture(ctx,mPaintDevice->texture(),size(),mPaintDevice->size(),rect,rect); + ww->glContext()->swapBuffers(); +} + +void QWaylandGLWindowSurface::resize(const QSize &size) +{ + QWindowSurface::resize(size); + window()->platformWindow()->glContext()->makeCurrent(); + delete mPaintDevice; + mPaintDevice = new QGLFramebufferObject(size,QGLFramebufferObject::CombinedDepthStencil,GL_TEXTURE_2D,GL_RGBA); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.h b/src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.h new file mode 100644 index 0000000..faff872 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/qwaylandglwindowsurface.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the config.tests of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDDRMSURFACE_H +#define QWAYLANDDRMSURFACE_H + +#include "qwaylanddisplay.h" + +#include + +class QGLFramebufferObject; + +class QWaylandGLWindowSurface : public QWindowSurface +{ +public: + QWaylandGLWindowSurface(QWidget *window); + ~QWaylandGLWindowSurface(); + + void beginPaint(const QRegion &); + + QPaintDevice *paintDevice(); + void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); + + void resize(const QSize &size); + +private: + QWaylandDisplay *mDisplay; + QGLFramebufferObject *mPaintDevice; +}; + +#endif // QWAYLANDDRMSURFACE_H diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglinclude.h b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglinclude.h new file mode 100644 index 0000000..778c3db --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglinclude.h @@ -0,0 +1,16 @@ +#ifndef QWAYLANDEGLINCLUDE_H +#define QWAYLANDEGLINCLUDE_H + +#include + +#include + +#define GL_GLEXT_PROTOTYPES +#include +#include + +#define EGL_EGLEXT_PROTOTYPES +#include +#include + +#endif // QWAYLANDEGLINCLUDE_H diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.cpp b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.cpp new file mode 100644 index 0000000..eb46bc7 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.cpp @@ -0,0 +1,48 @@ +#include "qwaylandeglintegration.h" + +#include "qwaylandeglwindow.h" + +QWaylandEglIntegration::QWaylandEglIntegration(struct wl_display *waylandDisplay) + : mWaylandDisplay(waylandDisplay) + , mNativeEglDisplay(wl_egl_display_create(mWaylandDisplay)) +{ +} + +QWaylandEglIntegration::~QWaylandEglIntegration() +{ + eglTerminate(mEglDisplay); +} + +void QWaylandEglIntegration::initialize() +{ + EGLint major,minor; + mEglDisplay = eglGetDisplay((EGLNativeDisplayType)mNativeEglDisplay); + if (mEglDisplay == NULL) { + qWarning("EGL not available"); + } else { + if (!eglInitialize(mEglDisplay, &major, &minor)) { + qWarning("failed to initialize EGL display"); + return; + } + } +} + +QWaylandWindow *QWaylandEglIntegration::createEglWindow(QWidget *window) +{ + return new QWaylandEglWindow(window); +} + +EGLDisplay QWaylandEglIntegration::eglDisplay() const +{ + return mEglDisplay; +} + +wl_egl_display * QWaylandEglIntegration::nativeDisplay() const +{ + return mNativeEglDisplay; +} + +QWaylandGLIntegration *QWaylandGLIntegration::createEglIntegration(wl_display *waylandDisplay) +{ + return new QWaylandEglIntegration(waylandDisplay); +} diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.h b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.h new file mode 100644 index 0000000..8b166ce --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.h @@ -0,0 +1,32 @@ +#ifndef QWAYLANDEGLINTEGRATION_H +#define QWAYLANDEGLINTEGRATION_H + +#include "gl_integration/qwaylandglintegration.h" + +#include "qwaylandeglinclude.h" + +class QWaylandWindow; +class QWidget; + +class QWaylandEglIntegration : public QWaylandGLIntegration +{ +public: + QWaylandEglIntegration(struct wl_display *waylandDisplay); + ~QWaylandEglIntegration(); + + void initialize(); + + QWaylandWindow *createEglWindow(QWidget *window); + + EGLDisplay eglDisplay() const; + struct wl_egl_display *nativeDisplay() const; +private: + struct wl_display *mWaylandDisplay; + + EGLDisplay mEglDisplay; + struct wl_egl_display *mNativeEglDisplay; + + +}; + +#endif // QWAYLANDEGLINTEGRATION_H diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp new file mode 100644 index 0000000..a9aa46f --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the config.tests of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandeglwindow.h" + +#include "qwaylandscreen.h" +#include "qwaylandglcontext.h" + +QWaylandEglWindow::QWaylandEglWindow(QWidget *window) + : QWaylandWindow(window) + , mGLContext(0) + , mWaylandEglWindow(0) +{ + mEglIntegration = static_cast(mDisplay->eglIntegration()); + //super creates a new surface + newSurfaceCreated(); +} + +QWaylandEglWindow::~QWaylandEglWindow() +{ + delete mGLContext; +} + +QWaylandWindow::WindowType QWaylandEglWindow::windowType() const +{ + return QWaylandWindow::Egl; +} + +void QWaylandEglWindow::setGeometry(const QRect &rect) +{ + QWaylandWindow::setGeometry(rect); + if (mWaylandEglWindow) { + wl_egl_window_resize(mWaylandEglWindow,rect.width(),rect.height(),0,0); + } +} + +void QWaylandEglWindow::setParent(const QPlatformWindow *parent) +{ + const QWaylandWindow *wParent = static_cast(parent); + + mParentWindow = wParent; +} + +QPlatformGLContext * QWaylandEglWindow::glContext() const +{ + if (!mGLContext) { + QWaylandEglWindow *that = const_cast(this); + that->mGLContext = new QWaylandGLContext(mEglIntegration->eglDisplay(),widget()->platformWindowFormat()); + + EGLNativeWindowType window(reinterpret_cast(mWaylandEglWindow)); + EGLSurface surface = eglCreateWindowSurface(mEglIntegration->eglDisplay(),mGLContext->eglConfig(),window,NULL); + that->mGLContext->setEglSurface(surface); + } + + return mGLContext; +} + +void QWaylandEglWindow::newSurfaceCreated() +{ + if (mWaylandEglWindow) { + wl_egl_window_destroy(mWaylandEglWindow); + } + wl_visual *visual = QWaylandScreen::waylandScreenFromWidget(widget())->visual(); + QSize size = geometry().size(); + if (!size.isValid()) + size = QSize(0,0); + + mWaylandEglWindow = wl_egl_window_create(mEglIntegration->nativeDisplay(),mSurface,size.width(),size.height(),visual); + if (mGLContext) { + EGLNativeWindowType window(reinterpret_cast(mWaylandEglWindow)); + EGLSurface surface = eglCreateWindowSurface(mEglIntegration->eglDisplay(),mGLContext->eglConfig(),window,NULL); + mGLContext->setEglSurface(surface); + } +} diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h new file mode 100644 index 0000000..ef1e02a --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the config.tests of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDEGLWINDOW_H +#define QWAYLANDEGLWINDOW_H + +#include "qwaylandwindow.h" +#include "qwaylandeglinclude.h" +#include "qwaylandeglintegration.h" + +class QWaylandGLContext; + +class QWaylandEglWindow : public QWaylandWindow +{ +public: + QWaylandEglWindow(QWidget *window); + ~QWaylandEglWindow(); + WindowType windowType() const; + void setGeometry(const QRect &rect); + void setParent(const QPlatformWindow *parent); + QPlatformGLContext *glContext() const; +protected: + void newSurfaceCreated(); +private: + QWaylandEglIntegration *mEglIntegration; + QWaylandGLContext *mGLContext; + struct wl_egl_window *mWaylandEglWindow; + EGLConfig mConfig; + + const QWaylandWindow *mParentWindow; +}; + +#endif // QWAYLANDEGLWINDOW_H diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.cpp b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.cpp new file mode 100644 index 0000000..4444229 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandglcontext.h" + +#include "qwaylanddisplay.h" +#include "qwaylandwindow.h" + +#include "../../../eglconvenience/qeglconvenience.h" + +#include +#include +#include + +Q_GLOBAL_STATIC(QMutex,qt_defaultSharedContextMutex) + +QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, const QPlatformWindowFormat &format) + : QPlatformGLContext() + , mEglDisplay(eglDisplay) + , mSurface(EGL_NO_SURFACE) + , mConfig(q_configFromQPlatformWindowFormat(mEglDisplay,format,true)) + , mFormat(qt_qPlatformWindowFormatFromConfig(mEglDisplay,mConfig)) +{ + QPlatformGLContext *sharePlatformContext = 0; + if (format.useDefaultSharedContext()) { + if (!QPlatformGLContext::defaultSharedContext()) { + if (qt_defaultSharedContextMutex()->tryLock()){ + createDefaultSharedContex(eglDisplay); + qt_defaultSharedContextMutex()->unlock(); + } else { + qt_defaultSharedContextMutex()->lock(); //wait to the the shared context is created + qt_defaultSharedContextMutex()->unlock(); + } + } + sharePlatformContext = QPlatformGLContext::defaultSharedContext(); + } else { + sharePlatformContext = format.sharedGLContext(); + } + mFormat.setSharedContext(sharePlatformContext); + EGLContext shareEGLContext = EGL_NO_CONTEXT; + if (sharePlatformContext) + shareEGLContext = static_cast(sharePlatformContext)->mContext; + + eglBindAPI(EGL_OPENGL_ES_API); + + QVector eglContextAttrs; + eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION); + eglContextAttrs.append(2); + eglContextAttrs.append(EGL_NONE); + + mContext = eglCreateContext(mEglDisplay, mConfig, + shareEGLContext, eglContextAttrs.constData()); +} + +QWaylandGLContext::QWaylandGLContext() + : QPlatformGLContext() + , mEglDisplay(0) + , mContext(EGL_NO_CONTEXT) + , mSurface(EGL_NO_SURFACE) + , mConfig(0) +{ } + +QWaylandGLContext::~QWaylandGLContext() +{ + eglDestroyContext(mEglDisplay,mContext); +} + +void QWaylandGLContext::makeCurrent() +{ + QPlatformGLContext::makeCurrent(); + if (mSurface == EGL_NO_SURFACE) { + qWarning("makeCurrent with EGL_NO_SURFACE"); + } + eglMakeCurrent(mEglDisplay, mSurface, mSurface, mContext); +} + +void QWaylandGLContext::doneCurrent() +{ + QPlatformGLContext::doneCurrent(); + eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); +} + +void QWaylandGLContext::swapBuffers() +{ + eglSwapBuffers(mEglDisplay,mSurface); +} + +void *QWaylandGLContext::getProcAddress(const QString &string) +{ + return (void *) eglGetProcAddress(string.toLatin1().data()); +} + +void QWaylandGLContext::createDefaultSharedContex(EGLDisplay display) +{ + QVector eglContextAttrs; + eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION); + eglContextAttrs.append(2); + eglContextAttrs.append(EGL_NONE); + + QWaylandGLContext *defaultSharedContext = new QWaylandGLContext; + defaultSharedContext->mEglDisplay = display; + defaultSharedContext->mContext = eglCreateContext(mEglDisplay,mConfig, + EGL_NO_CONTEXT, eglContextAttrs.constData()); + QPlatformGLContext::setDefaultSharedContext(defaultSharedContext); +} + +void QWaylandGLContext::setEglSurface(EGLSurface surface) +{ + doneCurrent(); + mSurface = surface; +} + +EGLConfig QWaylandGLContext::eglConfig() const +{ + return mConfig; +} + diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.h b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.h new file mode 100644 index 0000000..d530b1c --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDGLCONTEXT_H +#define QWAYLANDGLCONTEXT_H + +#include "qwaylanddisplay.h" + +#include + +#include "qwaylandeglinclude.h" + +class QWaylandWindow; +class QWaylandGLWindowSurface; + +class QWaylandGLContext : public QPlatformGLContext { +public: + QWaylandGLContext(EGLDisplay eglDisplay, const QPlatformWindowFormat &format); + ~QWaylandGLContext(); + void makeCurrent(); + void doneCurrent(); + void swapBuffers(); + void* getProcAddress(const QString&); + + QPlatformWindowFormat platformWindowFormat() const { return mFormat; } + + void setEglSurface(EGLSurface surface); + EGLConfig eglConfig() const; +private: + EGLDisplay mEglDisplay; + + EGLContext mContext; + EGLSurface mSurface; + EGLConfig mConfig; + QPlatformWindowFormat mFormat; + + void createDefaultSharedContex(EGLDisplay eglDisplay); + QWaylandGLContext(); + +}; + + +#endif // QWAYLANDGLCONTEXT_H diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/wayland_egl.pri b/src/plugins/platforms/wayland/gl_integration/wayland_egl/wayland_egl.pri new file mode 100644 index 0000000..bc97864 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/wayland_egl.pri @@ -0,0 +1,12 @@ +LIBS += -lwayland-egl -lEGL +INCLUDEPATH += $$PWD +SOURCES += $$PWD/qwaylandeglintegration.cpp \ + $$PWD/qwaylandglcontext.cpp \ + $$PWD/qwaylandeglwindow.cpp \ + $$PWD/../../../eglconvenience/qeglconvenience.cpp + +HEADERS += $$PWD/qwaylandeglintegration.h \ + $$PWD/qwaylandglcontext.h \ + $$PWD/qwaylandeglwindow.h \ + $$PWD/../../../eglconvenience/qeglconvenience.h \ + gl_integration/wayland_egl/qwaylandeglinclude.h diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index 27f4334..eebc9de 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -46,6 +46,10 @@ #include "qwaylandcursor.h" #include "qwaylandinputdevice.h" +#ifdef QT_WAYLAND_GL_SUPPORT +#include "gl_integration/qwaylandglintegration.h" +#endif + #include #include #include @@ -78,9 +82,9 @@ struct wl_visual *QWaylandDisplay::argbPremultipliedVisual() return wl_display_get_premultiplied_argb_visual(mDisplay); } -struct wl_egl_display *QWaylandDisplay::nativeDisplay() +QWaylandGLIntegration * QWaylandDisplay::eglIntegration() { - return mNativeEglDisplay; + return mEglIntegration; } void QWaylandDisplay::shellHandleConfigure(void *data, struct wl_shell *shell, @@ -176,9 +180,6 @@ void QWaylandDisplay::flushRequests(void) QWaylandDisplay::QWaylandDisplay(void) : mWriteNotifier(0) { -#ifdef QT_WAYLAND_GL_SUPPORT - EGLint major, minor; -#endif mDisplay = wl_display_connect(NULL); if (mDisplay == NULL) { fprintf(stderr, "failed to create display: %m\n"); @@ -189,25 +190,13 @@ QWaylandDisplay::QWaylandDisplay(void) QWaylandDisplay::displayHandleGlobal, this); #ifdef QT_WAYLAND_GL_SUPPORT - mNativeEglDisplay = wl_egl_display_create(mDisplay); -#else - mNativeEglDisplay = 0; + mEglIntegration = QWaylandGLIntegration::createEglIntegration(mDisplay); #endif readEvents(); #ifdef QT_WAYLAND_GL_SUPPORT - mEglDisplay = eglGetDisplay((EGLNativeDisplayType)mNativeEglDisplay); - if (mEglDisplay == NULL) { - qWarning("EGL not available"); - } else { - if (!eglInitialize(mEglDisplay, &major, &minor)) { - qWarning("failed to initialize EGL display"); - return; - } - } -#else - mEglDisplay = 0; + mEglIntegration->initialize(); #endif int fd = wl_display_get_fd(mDisplay, sourceUpdate, this); @@ -225,7 +214,7 @@ QWaylandDisplay::~QWaylandDisplay(void) { close(mFd); #ifdef QT_WAYLAND_GL_SUPPORT - eglTerminate(mEglDisplay); + delete mEglIntegration; #endif wl_display_destroy(mDisplay); } @@ -245,3 +234,4 @@ void QWaylandDisplay::frameCallback(wl_display_frame_func_t func, void *data) { wl_display_frame_callback(mDisplay, func, data); } + diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.h b/src/plugins/platforms/wayland/qwaylanddisplay.h index d994ffe..535dcd6 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.h +++ b/src/plugins/platforms/wayland/qwaylanddisplay.h @@ -44,18 +44,15 @@ #include #include -#include -#include -#include -#include -#include "qwaylandinclude.h" +#include class QWaylandInputDevice; class QSocketNotifier; class QWaylandBuffer; class QPlatformScreen; class QWaylandScreen; +class QWaylandGLIntegration; class QWaylandDisplay : public QObject { Q_OBJECT @@ -73,9 +70,10 @@ public: struct wl_visual *rgbVisual(); struct wl_visual *argbVisual(); struct wl_visual *argbPremultipliedVisual(); - struct wl_egl_display *nativeDisplay(); - EGLDisplay eglDisplay() { return mEglDisplay; } +#ifdef QT_WAYLAND_GL_SUPPORT + QWaylandGLIntegration *eglIntegration(); +#endif void setCursor(QWaylandBuffer *buffer, int32_t x, int32_t y); void syncCallback(wl_display_sync_func_t func, void *data); @@ -98,8 +96,9 @@ private: QList mInputDevices; QSocketNotifier *mReadNotifier; QSocketNotifier *mWriteNotifier; - EGLDisplay mEglDisplay; - struct wl_egl_display *mNativeEglDisplay; +#ifdef QT_WAYLAND_GL_SUPPORT + QWaylandGLIntegration *mEglIntegration; +#endif static void displayHandleGlobal(struct wl_display *display, uint32_t id, diff --git a/src/plugins/platforms/wayland/qwaylanddrmsurface.cpp b/src/plugins/platforms/wayland/qwaylanddrmsurface.cpp deleted file mode 100644 index a8bc352..0000000 --- a/src/plugins/platforms/wayland/qwaylanddrmsurface.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwaylanddrmsurface.h" - -#include "qwaylanddisplay.h" -#include "qwaylandwindow.h" -#include "qwaylandscreen.h" - -#include -#include - -#include - -QT_BEGIN_NAMESPACE - - - -static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &br) -{ - const GLenum target = GL_TEXTURE_2D; - QRectF src = br.isEmpty() - ? QRectF(QPointF(), texSize) - : QRectF(QPointF(br.x(), texSize.height() - br.bottom()), br.size()); - - if (target == GL_TEXTURE_2D) { - qreal width = texSize.width(); - qreal height = texSize.height(); - - src.setLeft(src.left() / width); - src.setRight(src.right() / width); - src.setTop(src.top() / height); - src.setBottom(src.bottom() / height); - } - - const GLfloat tx1 = src.left(); - const GLfloat tx2 = src.right(); - const GLfloat ty1 = src.top(); - const GLfloat ty2 = src.bottom(); - - GLfloat texCoordArray[4*2] = { - tx1, ty2, tx2, ty2, tx2, ty1, tx1, ty1 - }; - - GLfloat vertexArray[4*2]; - vertexArray[0] = rect.left(); vertexArray[1] = rect.top(); - vertexArray[2] = rect.right(); vertexArray[3] = rect.top(); - vertexArray[4] = rect.right(); vertexArray[5] = rect.bottom(); - vertexArray[6] = rect.left(); vertexArray[7] = rect.bottom(); - - glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, vertexArray); - glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, texCoordArray); - - glBindTexture(target, tex_id); - - glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR); - glEnableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR); - glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR); - - glBindTexture(target, 0); -} - -static void blitTexture(QGLContext *ctx, GLuint texture, const QSize &viewport, const QSize &texSize, const QRect &targetRect, const QRect &sourceRect) -{ - glDisable(GL_DEPTH_TEST); - glDisable(GL_SCISSOR_TEST); - glDisable(GL_BLEND); - glViewport(0, 0, viewport.width(), viewport.height()); - - QGLShaderProgram *blitProgram = - QGLEngineSharedShaders::shadersForContext(ctx)->blitProgram(); - blitProgram->bind(); - blitProgram->setUniformValue("imageTexture", 0 /*QT_IMAGE_TEXTURE_UNIT*/); - - // The shader manager's blit program does not multiply the - // vertices by the pmv matrix, so we need to do the effect - // of the orthographic projection here ourselves. - QRectF r; - qreal w = viewport.width(); - qreal h = viewport.height(); - r.setLeft((targetRect.left() / w) * 2.0f - 1.0f); - if (targetRect.right() == (viewport.width() - 1)) - r.setRight(1.0f); - else - r.setRight((targetRect.right() / w) * 2.0f - 1.0f); - r.setBottom((targetRect.top() / h) * 2.0f - 1.0f); - if (targetRect.bottom() == (viewport.height() - 1)) - r.setTop(1.0f); - else - r.setTop((targetRect.bottom() / w) * 2.0f - 1.0f); - - drawTexture(r, texture, texSize, sourceRect); -} - -QWaylandDrmWindowSurface::QWaylandDrmWindowSurface(QWidget *window) - : QWindowSurface(window) - , mDisplay(QWaylandScreen::waylandScreenFromWidget(window)->display()) - , mPaintDevice(0) -{ - -} - -QWaylandDrmWindowSurface::~QWaylandDrmWindowSurface() -{ - delete mPaintDevice; -} - -QPaintDevice *QWaylandDrmWindowSurface::paintDevice() -{ - return mPaintDevice; -} - -void QWaylandDrmWindowSurface::beginPaint(const QRegion &) -{ - window()->platformWindow()->glContext()->makeCurrent(); - glClearColor(0,0,0,0xff); - glClear(GL_COLOR_BUFFER_BIT); -} - -void QWaylandDrmWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) -{ - Q_UNUSED(offset); - Q_UNUSED(region); - QWaylandWindow *ww = (QWaylandWindow *) widget->platformWindow(); - - if (mPaintDevice->isBound()) - mPaintDevice->release(); - - QRect rect(0,0,size().width(),size().height()); - QGLContext *ctx = QGLContext::fromPlatformGLContext(ww->glContext()); - blitTexture(ctx,mPaintDevice->texture(),size(),mPaintDevice->size(),rect,rect); - ww->glContext()->swapBuffers(); -} - -void QWaylandDrmWindowSurface::resize(const QSize &size) -{ - QWindowSurface::resize(size); - window()->platformWindow()->glContext()->makeCurrent(); - delete mPaintDevice; - mPaintDevice = new QGLFramebufferObject(size,QGLFramebufferObject::CombinedDepthStencil,GL_TEXTURE_2D,GL_RGBA); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/wayland/qwaylanddrmsurface.h b/src/plugins/platforms/wayland/qwaylanddrmsurface.h deleted file mode 100644 index 78418ee..0000000 --- a/src/plugins/platforms/wayland/qwaylanddrmsurface.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the config.tests of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWAYLANDDRMSURFACE_H -#define QWAYLANDDRMSURFACE_H - -#include "qwaylanddisplay.h" - -#include - -class QGLFramebufferObject; - -class QWaylandDrmWindowSurface : public QWindowSurface -{ -public: - QWaylandDrmWindowSurface(QWidget *window); - ~QWaylandDrmWindowSurface(); - - void beginPaint(const QRegion &); - - QPaintDevice *paintDevice(); - void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - - void resize(const QSize &size); - -private: - - QWaylandDisplay *mDisplay; - QGLFramebufferObject *mPaintDevice; -}; - -#endif // QWAYLANDDRMSURFACE_H diff --git a/src/plugins/platforms/wayland/qwaylandeglwindow.cpp b/src/plugins/platforms/wayland/qwaylandeglwindow.cpp deleted file mode 100644 index ed54bb9..0000000 --- a/src/plugins/platforms/wayland/qwaylandeglwindow.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the config.tests of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwaylandeglwindow.h" - -#include "qwaylandscreen.h" -#include "qwaylandglcontext.h" -#include "qwaylandinclude.h" - -QWaylandEglWindow::QWaylandEglWindow(QWidget *window) - : QWaylandWindow(window) - , mGLContext(0) - , mWaylandEglWindow(0) -{ - //super creates a new surface - newSurfaceCreated(); -} - -QWaylandEglWindow::~QWaylandEglWindow() -{ - if (mGLContext) - delete mGLContext; -} - -QWaylandWindow::WindowType QWaylandEglWindow::windowType() const -{ - return QWaylandWindow::Egl; -} - -void QWaylandEglWindow::setGeometry(const QRect &rect) -{ - QWaylandWindow::setGeometry(rect); - if (mWaylandEglWindow) { - wl_egl_window_resize(mWaylandEglWindow,rect.width(),rect.height(),0,0); - } -} - -void QWaylandEglWindow::setParent(const QPlatformWindow *parent) -{ - const QWaylandWindow *wParent = static_cast(parent); - - mParentWindow = wParent; -} - -QPlatformGLContext * QWaylandEglWindow::glContext() const -{ - if (!mGLContext) { - QWaylandEglWindow *that = const_cast(this); - that->mGLContext = new QWaylandGLContext(that->mDisplay,widget()->platformWindowFormat()); - - EGLNativeWindowType window(reinterpret_cast(mWaylandEglWindow)); - EGLSurface surface = eglCreateWindowSurface(mDisplay->eglDisplay(),mGLContext->eglConfig(),window,NULL); - that->mGLContext->setEglSurface(surface); - } - - return mGLContext; -} - -void QWaylandEglWindow::newSurfaceCreated() -{ - if (mWaylandEglWindow) { - wl_egl_window_destroy(mWaylandEglWindow); - } - wl_visual *visual = QWaylandScreen::waylandScreenFromWidget(widget())->visual(); - QSize size = geometry().size(); - if (!size.isValid()) - size = QSize(0,0); - - mWaylandEglWindow = wl_egl_window_create(mDisplay->nativeDisplay(),mSurface,size.width(),size.height(),visual); - if (mGLContext) { - EGLNativeWindowType window(reinterpret_cast(mWaylandEglWindow)); - EGLSurface surface = eglCreateWindowSurface(mDisplay->eglDisplay(),mGLContext->eglConfig(),window,NULL); - mGLContext->setEglSurface(surface); - } -} diff --git a/src/plugins/platforms/wayland/qwaylandeglwindow.h b/src/plugins/platforms/wayland/qwaylandeglwindow.h deleted file mode 100644 index 4b3bb5b..0000000 --- a/src/plugins/platforms/wayland/qwaylandeglwindow.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the config.tests of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWAYLANDEGLWINDOW_H -#define QWAYLANDEGLWINDOW_H - -#include "qwaylandwindow.h" - -class QWaylandGLContext; - -class QWaylandEglWindow : public QWaylandWindow -{ -public: - QWaylandEglWindow(QWidget *window); - ~QWaylandEglWindow(); - WindowType windowType() const; - void setGeometry(const QRect &rect); - void setParent(const QPlatformWindow *parent); - QPlatformGLContext *glContext() const; -protected: - void newSurfaceCreated(); -private: - QWaylandGLContext *mGLContext; - struct wl_egl_window *mWaylandEglWindow; - EGLConfig mConfig; - - const QWaylandWindow *mParentWindow; -}; - -#endif // QWAYLANDEGLWINDOW_H diff --git a/src/plugins/platforms/wayland/qwaylandglcontext.cpp b/src/plugins/platforms/wayland/qwaylandglcontext.cpp deleted file mode 100644 index 3720567..0000000 --- a/src/plugins/platforms/wayland/qwaylandglcontext.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwaylandglcontext.h" - -#include "qwaylanddisplay.h" -#include "qwaylandwindow.h" -#include "qwaylanddrmsurface.h" - -#include "../eglconvenience/qeglconvenience.h" - -#include -#include - -Q_GLOBAL_STATIC(QMutex,qt_defaultSharedContextMutex) - -QWaylandGLContext::QWaylandGLContext(QWaylandDisplay *wd, const QPlatformWindowFormat &format) - : QPlatformGLContext() - , mDisplay(wd) - , mSurface(EGL_NO_SURFACE) - , mConfig(q_configFromQPlatformWindowFormat(mDisplay->eglDisplay(),format,true)) - , mFormat(qt_qPlatformWindowFormatFromConfig(mDisplay->eglDisplay(),mConfig)) -{ - QPlatformGLContext *sharePlatformContext = 0; - if (format.useDefaultSharedContext()) { - if (!QPlatformGLContext::defaultSharedContext()) { - if (qt_defaultSharedContextMutex()->tryLock()){ - createDefaultSharedContex(wd); - qt_defaultSharedContextMutex()->unlock(); - } else { - qt_defaultSharedContextMutex()->lock(); //wait to the the shared context is created - qt_defaultSharedContextMutex()->unlock(); - } - } - sharePlatformContext = QPlatformGLContext::defaultSharedContext(); - } else { - sharePlatformContext = format.sharedGLContext(); - } - mFormat.setSharedContext(sharePlatformContext); - EGLContext shareEGLContext = EGL_NO_CONTEXT; - if (sharePlatformContext) - shareEGLContext = static_cast(sharePlatformContext)->mContext; - - eglBindAPI(EGL_OPENGL_ES_API); - - QVector eglContextAttrs; - eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION); - eglContextAttrs.append(2); - eglContextAttrs.append(EGL_NONE); - - mContext = eglCreateContext(mDisplay->eglDisplay(), mConfig, - shareEGLContext, eglContextAttrs.constData()); -} - -QWaylandGLContext::QWaylandGLContext() - : QPlatformGLContext() - , mDisplay(0) - , mContext(EGL_NO_CONTEXT) - , mSurface(EGL_NO_SURFACE) - , mConfig(0) -{ } - -QWaylandGLContext::~QWaylandGLContext() -{ - eglDestroyContext(mDisplay->eglDisplay(),mContext); -} - -void QWaylandGLContext::makeCurrent() -{ - QPlatformGLContext::makeCurrent(); - if (mSurface == EGL_NO_SURFACE) { - qWarning("makeCurrent with EGL_NO_SURFACE"); - } - eglMakeCurrent(mDisplay->eglDisplay(), mSurface, mSurface, mContext); -} - -void QWaylandGLContext::doneCurrent() -{ - QPlatformGLContext::doneCurrent(); - eglMakeCurrent(mDisplay->eglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); -} - -void QWaylandGLContext::swapBuffers() -{ - eglSwapBuffers(mDisplay->eglDisplay(),mSurface); -} - -void *QWaylandGLContext::getProcAddress(const QString &string) -{ - return (void *) eglGetProcAddress(string.toLatin1().data()); -} - -void QWaylandGLContext::createDefaultSharedContex(QWaylandDisplay *display) -{ - QVector eglContextAttrs; - eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION); - eglContextAttrs.append(2); - eglContextAttrs.append(EGL_NONE); - - QWaylandGLContext *defaultSharedContext = new QWaylandGLContext; - defaultSharedContext->mDisplay = display; - defaultSharedContext->mContext = eglCreateContext(mDisplay->eglDisplay(),mConfig, - EGL_NO_CONTEXT, eglContextAttrs.constData()); - QPlatformGLContext::setDefaultSharedContext(defaultSharedContext); -} - -void QWaylandGLContext::setEglSurface(EGLSurface surface) -{ - doneCurrent(); - mSurface = surface; -} - -EGLConfig QWaylandGLContext::eglConfig() const -{ - return mConfig; -} - diff --git a/src/plugins/platforms/wayland/qwaylandglcontext.h b/src/plugins/platforms/wayland/qwaylandglcontext.h deleted file mode 100644 index dd319fd..0000000 --- a/src/plugins/platforms/wayland/qwaylandglcontext.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWAYLANDGLCONTEXT_H -#define QWAYLANDGLCONTEXT_H - -#include "qwaylanddisplay.h" - -#include - -class QWaylandWindow; -class QWaylandDrmWindowSurface; - -#include "qwaylandinclude.h" - -class QWaylandGLContext : public QPlatformGLContext { -public: - QWaylandGLContext(QWaylandDisplay *wd, const QPlatformWindowFormat &format); - ~QWaylandGLContext(); - void makeCurrent(); - void doneCurrent(); - void swapBuffers(); - void* getProcAddress(const QString&); - - QPlatformWindowFormat platformWindowFormat() const { return mFormat; } - - void setEglSurface(EGLSurface surface); - EGLConfig eglConfig() const; -private: - QWaylandDisplay *mDisplay; - - EGLContext mContext; - EGLSurface mSurface; - EGLConfig mConfig; - QPlatformWindowFormat mFormat; - - void createDefaultSharedContex(QWaylandDisplay *display); - QWaylandGLContext(); - -}; - - -#endif // QWAYLANDGLCONTEXT_H diff --git a/src/plugins/platforms/wayland/qwaylandinclude.h b/src/plugins/platforms/wayland/qwaylandinclude.h deleted file mode 100644 index 0135251..0000000 --- a/src/plugins/platforms/wayland/qwaylandinclude.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the config.tests of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** 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, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWAYLANDINCLUDE_H -#define QWAYLANDINCLUDE_H - -#include - -#ifdef QT_WAYLAND_GL_SUPPORT -#include - -#define GL_GLEXT_PROTOTYPES -#include -#include - -#define EGL_EGLEXT_PROTOTYPES - #include - #include - -#else -typedef void* EGLDisplay; -typedef void* EGLConfig; -#endif - -#endif // QWAYLANDINCLUDE_H diff --git a/src/plugins/platforms/wayland/qwaylandintegration.cpp b/src/plugins/platforms/wayland/qwaylandintegration.cpp index 267a037..be78b82 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.cpp +++ b/src/plugins/platforms/wayland/qwaylandintegration.cpp @@ -43,9 +43,7 @@ #include "qwaylanddisplay.h" #include "qwaylandshmsurface.h" -#include "qwaylanddrmsurface.h" #include "qwaylandshmwindow.h" -#include "qwaylandeglwindow.h" #include "qgenericunixfontdatabase.h" @@ -55,6 +53,8 @@ #include #ifdef QT_WAYLAND_GL_SUPPORT +#include "gl_integration/qwaylandglintegration.h" +#include "gl_integration/qwaylandglwindowsurface.h" #include #endif @@ -91,10 +91,11 @@ QPixmapData *QWaylandIntegration::createPixmapData(QPixmapData::PixelType type) QPlatformWindow *QWaylandIntegration::createPlatformWindow(QWidget *widget, WId winId) const { Q_UNUSED(winId); +#ifdef QT_WAYLAND_GL_SUPPORT bool useOpenGL = mUseOpenGL || (widget->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL); if (useOpenGL) - return new QWaylandEglWindow(widget); - + return mDisplay->eglIntegration()->createEglWindow(widget); +#endif return new QWaylandShmWindow(widget); } @@ -102,10 +103,11 @@ QWindowSurface *QWaylandIntegration::createWindowSurface(QWidget *widget, WId wi { Q_UNUSED(winId); Q_UNUSED(winId); +#ifdef QT_WAYLAND_GL_SUPPORT bool useOpenGL = mUseOpenGL || (widget->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenGL); if (useOpenGL) - return new QWaylandDrmWindowSurface(widget); - + return new QWaylandGLWindowSurface(widget); +#endif return new QWaylandShmWindowSurface(widget); } diff --git a/src/plugins/platforms/wayland/qwaylandwindow.h b/src/plugins/platforms/wayland/qwaylandwindow.h index 3b51ee7..afc214e 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.h +++ b/src/plugins/platforms/wayland/qwaylandwindow.h @@ -44,7 +44,6 @@ #include -#include #include "qwaylanddisplay.h" class QWaylandDisplay; diff --git a/src/plugins/platforms/wayland/wayland.pro b/src/plugins/platforms/wayland/wayland.pro index f78e4b3..b44857b 100644 --- a/src/plugins/platforms/wayland/wayland.pro +++ b/src/plugins/platforms/wayland/wayland.pro @@ -22,29 +22,21 @@ HEADERS = qwaylandintegration.h \ qwaylandwindow.h \ qwaylandscreen.h \ qwaylandshmsurface.h \ - qwaylanddrmsurface.h \ qwaylandbuffer.h \ - qwaylandinclude.h \ - qwaylandeglwindow.h \ qwaylandshmwindow.h INCLUDEPATH += $$QMAKE_INCDIR_WAYLAND LIBS += $$QMAKE_LIBS_WAYLAND QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_WAYLAND +INCLUDEPATH += $$PWD + contains(QT_CONFIG, opengles2) { + DEFINES += QT_WAYLAND_GL_SUPPORT QT += opengl - LIBS += -lwayland-egl -lEGL - - SOURCES += qwaylanddrmsurface.cpp \ - qwaylandglcontext.cpp \ - ../eglconvenience/qeglconvenience.cpp \ - qwaylandeglwindow.cpp - HEADERS += qwaylandglcontext.h \ - ../eglconvenience/qeglconvenience.h \ - - DEFINES += QT_WAYLAND_GL_SUPPORT + CONFIG += wayland_egl + include ($$PWD/gl_integration/gl_integration.pri) } include (../fontdatabases/genericunix/genericunix.pri) -- cgit v0.12