summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wayland/gl_integration/wayland_egl
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/wayland/gl_integration/wayland_egl')
-rw-r--r--src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.cpp25
-rw-r--r--src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.h11
-rw-r--r--src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp80
-rw-r--r--src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h22
-rw-r--r--src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.cpp70
-rw-r--r--src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.h28
-rw-r--r--src/plugins/platforms/wayland/gl_integration/wayland_egl/wayland_egl.pri2
7 files changed, 118 insertions, 120 deletions
diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.cpp b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.cpp
index d4deb01022..6e72a45bcd 100644
--- a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.cpp
+++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.cpp
@@ -44,11 +44,12 @@
#include "gl_integration/qwaylandglintegration.h"
#include "qwaylandeglwindow.h"
+#include "qwaylandglcontext.h"
#include <QtCore/QDebug>
QWaylandEglIntegration::QWaylandEglIntegration(struct wl_display *waylandDisplay)
- : mWaylandDisplay(waylandDisplay)
+ : m_waylandDisplay(waylandDisplay)
{
qDebug() << "Using Wayland-EGL";
}
@@ -56,31 +57,41 @@ QWaylandEglIntegration::QWaylandEglIntegration(struct wl_display *waylandDisplay
QWaylandEglIntegration::~QWaylandEglIntegration()
{
- eglTerminate(mEglDisplay);
+ eglTerminate(m_eglDisplay);
}
void QWaylandEglIntegration::initialize()
{
+ QByteArray eglPlatform = qgetenv("EGL_PLATFORM");
+ if (eglPlatform.isEmpty()) {
+ setenv("EGL_PLATFORM","wayland",true);
+ }
+
EGLint major,minor;
- mEglDisplay = eglGetDisplay(mWaylandDisplay);
- if (mEglDisplay == NULL) {
+ m_eglDisplay = eglGetDisplay(m_waylandDisplay);
+ if (m_eglDisplay == NULL) {
qWarning("EGL not available");
} else {
- if (!eglInitialize(mEglDisplay, &major, &minor)) {
+ if (!eglInitialize(m_eglDisplay, &major, &minor)) {
qWarning("failed to initialize EGL display");
return;
}
}
}
-QWaylandWindow *QWaylandEglIntegration::createEglWindow(QWidget *window)
+QWaylandWindow *QWaylandEglIntegration::createEglWindow(QWindow *window)
{
return new QWaylandEglWindow(window);
}
+QPlatformGLContext *QWaylandEglIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const
+{
+ return new QWaylandGLContext(m_eglDisplay, glFormat, share);
+}
+
EGLDisplay QWaylandEglIntegration::eglDisplay() const
{
- return mEglDisplay;
+ return m_eglDisplay;
}
QWaylandGLIntegration *QWaylandGLIntegration::createGLIntegration(QWaylandDisplay *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
index ea8b0f725c..5e39e39fe8 100644
--- a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.h
+++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglintegration.h
@@ -47,7 +47,7 @@
#include "qwaylandeglinclude.h"
class QWaylandWindow;
-class QWidget;
+class QWindow;
class QWaylandEglIntegration : public QWaylandGLIntegration
{
@@ -57,14 +57,15 @@ public:
void initialize();
- QWaylandWindow *createEglWindow(QWidget *window);
+ QWaylandWindow *createEglWindow(QWindow *window);
+ QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const;
EGLDisplay eglDisplay() const;
- struct wl_egl_display *nativeDisplay() const;
+
private:
- struct wl_display *mWaylandDisplay;
+ struct wl_display *m_waylandDisplay;
- EGLDisplay mEglDisplay;
+ EGLDisplay m_eglDisplay;
};
#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
index cd8b5b3524..245097ef6c 100644
--- a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp
+++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.cpp
@@ -44,19 +44,29 @@
#include "qwaylandscreen.h"
#include "qwaylandglcontext.h"
-QWaylandEglWindow::QWaylandEglWindow(QWidget *window)
+#include <QtPlatformSupport/private/qeglconvenience_p.h>
+
+#include <QtGui/QWindow>
+
+QWaylandEglWindow::QWaylandEglWindow(QWindow *window)
: QWaylandWindow(window)
- , mGLContext(0)
- , mWaylandEglWindow(0)
+ , m_waylandEglWindow(0)
+ , m_eglSurface(0)
+ , m_eglConfig(0)
+ , m_format(window->format())
{
- mEglIntegration = static_cast<QWaylandEglIntegration *>(mDisplay->eglIntegration());
+ m_eglIntegration = static_cast<QWaylandEglIntegration *>(mDisplay->eglIntegration());
+
//super creates a new surface
newSurfaceCreated();
}
QWaylandEglWindow::~QWaylandEglWindow()
{
- delete mGLContext;
+ if (m_eglSurface) {
+ eglDestroySurface(m_eglIntegration->eglDisplay(), m_eglSurface);
+ m_eglSurface = 0;
+ }
}
QWaylandWindow::WindowType QWaylandEglWindow::windowType() const
@@ -67,46 +77,46 @@ QWaylandWindow::WindowType QWaylandEglWindow::windowType() const
void QWaylandEglWindow::setGeometry(const QRect &rect)
{
QWaylandWindow::setGeometry(rect);
- if (mWaylandEglWindow) {
- wl_egl_window_resize(mWaylandEglWindow,rect.width(),rect.height(),0,0);
- }
+ if (m_waylandEglWindow)
+ wl_egl_window_resize(m_waylandEglWindow, rect.width(), rect.height(), 0, 0);
}
-void QWaylandEglWindow::setParent(const QPlatformWindow *parent)
+void QWaylandEglWindow::newSurfaceCreated()
{
- const QWaylandWindow *wParent = static_cast<const QWaylandWindow *>(parent);
+ if (m_waylandEglWindow)
+ wl_egl_window_destroy(m_waylandEglWindow);
- mParentWindow = wParent;
-}
-
-QPlatformGLContext * QWaylandEglWindow::glContext() const
-{
- if (!mGLContext) {
- QWaylandEglWindow *that = const_cast<QWaylandEglWindow *>(this);
- that->mGLContext = new QWaylandGLContext(mEglIntegration->eglDisplay(),widget()->platformWindowFormat());
+ wl_visual *visual = QWaylandScreen::waylandScreenFromWindow(window())->visual();
+ QSize size = geometry().size();
+ if (!size.isValid())
+ size = QSize(0,0);
- EGLNativeWindowType window(reinterpret_cast<EGLNativeWindowType>(mWaylandEglWindow));
- EGLSurface surface = eglCreateWindowSurface(mEglIntegration->eglDisplay(),mGLContext->eglConfig(),window,NULL);
- that->mGLContext->setEglSurface(surface);
+ if (m_eglSurface) {
+ eglDestroySurface(m_eglIntegration->eglDisplay(), m_eglSurface);
+ m_eglSurface = 0;
}
- return mGLContext;
+ m_waylandEglWindow = wl_egl_window_create(mSurface, size.width(), size.height(), visual);
}
-void QWaylandEglWindow::newSurfaceCreated()
+QSurfaceFormat QWaylandEglWindow::format() const
{
- 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);
+ return m_format;
+}
- mWaylandEglWindow = wl_egl_window_create(mSurface,size.width(),size.height(),visual);
- if (mGLContext) {
- EGLNativeWindowType window(reinterpret_cast<EGLNativeWindowType>(mWaylandEglWindow));
- EGLSurface surface = eglCreateWindowSurface(mEglIntegration->eglDisplay(),mGLContext->eglConfig(),window,NULL);
- mGLContext->setEglSurface(surface);
+EGLSurface QWaylandEglWindow::eglSurface() const
+{
+ if (!m_waylandEglWindow)
+ return 0;
+
+ if (!m_eglSurface) {
+ if (!m_eglConfig)
+ m_eglConfig = q_configFromGLFormat(m_eglIntegration->eglDisplay(), window()->format(), true);
+
+ EGLNativeWindowType window = m_waylandEglWindow;
+ m_eglSurface = eglCreateWindowSurface(m_eglIntegration->eglDisplay(), m_eglConfig, window, 0);
}
+
+ return m_eglSurface;
}
+
diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h
index 6d2038824a..d435a511c4 100644
--- a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h
+++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandeglwindow.h
@@ -51,20 +51,28 @@ class QWaylandGLContext;
class QWaylandEglWindow : public QWaylandWindow
{
public:
- QWaylandEglWindow(QWidget *window);
+ QWaylandEglWindow(QWindow *window);
~QWaylandEglWindow();
WindowType windowType() const;
void setGeometry(const QRect &rect);
- void setParent(const QPlatformWindow *parent);
- QPlatformGLContext *glContext() const;
+
+ EGLSurface eglSurface() const;
+
+ QSurfaceFormat format() const;
+
protected:
void newSurfaceCreated();
+
private:
- QWaylandEglIntegration *mEglIntegration;
- QWaylandGLContext *mGLContext;
- struct wl_egl_window *mWaylandEglWindow;
+ QWaylandEglIntegration *m_eglIntegration;
+ struct wl_egl_window *m_waylandEglWindow;
+
+ const QWaylandWindow *m_parentWindow;
+
+ mutable EGLSurface m_eglSurface;
+ mutable EGLConfig m_eglConfig;
- const QWaylandWindow *mParentWindow;
+ QSurfaceFormat m_format;
};
#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
index 0f27501c71..d3ece7c7a9 100644
--- a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.cpp
+++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.cpp
@@ -43,26 +43,21 @@
#include "qwaylanddisplay.h"
#include "qwaylandwindow.h"
+#include "qwaylandeglwindow.h"
-#include "../../../eglconvenience/qeglconvenience.h"
+#include <QtPlatformSupport/private/qeglconvenience_p.h>
#include <QtGui/QPlatformGLContext>
-#include <QtGui/QPlatformWindowFormat>
+#include <QtGui/QSurfaceFormat>
#include <QtCore/QMutex>
-QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, const QPlatformWindowFormat &format)
+QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, const QSurfaceFormat &format, QPlatformGLContext *share)
: QPlatformGLContext()
- , mEglDisplay(eglDisplay)
- , mSurface(EGL_NO_SURFACE)
- , mConfig(q_configFromQPlatformWindowFormat(mEglDisplay,format,true))
- , mFormat(qt_qPlatformWindowFormatFromConfig(mEglDisplay,mConfig))
+ , m_eglDisplay(eglDisplay)
+ , m_config(q_configFromGLFormat(m_eglDisplay, format, true))
+ , m_format(q_glFormatFromConfig(m_eglDisplay, m_config))
{
- QPlatformGLContext *sharePlatformContext = 0;
- sharePlatformContext = format.sharedGLContext();
- mFormat.setSharedContext(sharePlatformContext);
- EGLContext shareEGLContext = EGL_NO_CONTEXT;
- if (sharePlatformContext)
- shareEGLContext = static_cast<const QWaylandGLContext*>(sharePlatformContext)->mContext;
+ EGLContext shareEGLContext = share ? static_cast<QWaylandGLContext *>(share)->eglContext() : EGL_NO_CONTEXT;
eglBindAPI(EGL_OPENGL_ES_API);
@@ -71,63 +66,38 @@ QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, const QPlatformWindo
eglContextAttrs.append(2);
eglContextAttrs.append(EGL_NONE);
- mContext = eglCreateContext(mEglDisplay, mConfig,
- shareEGLContext, eglContextAttrs.constData());
+ m_context = eglCreateContext(m_eglDisplay, m_config, shareEGLContext, eglContextAttrs.constData());
}
-QWaylandGLContext::QWaylandGLContext()
- : QPlatformGLContext()
- , mEglDisplay(0)
- , mContext(EGL_NO_CONTEXT)
- , mSurface(EGL_NO_SURFACE)
- , mConfig(0)
-{ }
-
QWaylandGLContext::~QWaylandGLContext()
{
- eglDestroyContext(mEglDisplay,mContext);
+ eglDestroyContext(m_eglDisplay, m_context);
}
-void QWaylandGLContext::makeCurrent()
+bool QWaylandGLContext::makeCurrent(QPlatformSurface *surface)
{
- QPlatformGLContext::makeCurrent();
- if (mSurface == EGL_NO_SURFACE) {
- qWarning("makeCurrent with EGL_NO_SURFACE");
- }
- eglMakeCurrent(mEglDisplay, mSurface, mSurface, mContext);
+ EGLSurface eglSurface = static_cast<QWaylandEglWindow *>(surface)->eglSurface();
+ return eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_context);
}
void QWaylandGLContext::doneCurrent()
{
- QPlatformGLContext::doneCurrent();
- eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-}
-
-void QWaylandGLContext::swapBuffers()
-{
- eglSwapBuffers(mEglDisplay,mSurface);
+ eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
-void *QWaylandGLContext::getProcAddress(const QString &string)
+void QWaylandGLContext::swapBuffers(QPlatformSurface *surface)
{
- return (void *) eglGetProcAddress(string.toLatin1().data());
+ EGLSurface eglSurface = static_cast<QWaylandEglWindow *>(surface)->eglSurface();
+ eglSwapBuffers(m_eglDisplay, eglSurface);
}
-void QWaylandGLContext::setEglSurface(EGLSurface surface)
+void (*QWaylandGLContext::getProcAddress(const QByteArray &procName)) ()
{
- bool wasCurrent = false;
- if (QPlatformGLContext::currentContext() == this) {
- wasCurrent = true;
- doneCurrent();
- }
- mSurface = surface;
- if (wasCurrent) {
- makeCurrent();
- }
+ return eglGetProcAddress(procName.constData());
}
EGLConfig QWaylandGLContext::eglConfig() const
{
- return mConfig;
+ return m_config;
}
diff --git a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.h b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.h
index 2c6feb498c..592f3d18f5 100644
--- a/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.h
+++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/qwaylandglcontext.h
@@ -53,27 +53,27 @@ class QWaylandGLWindowSurface;
class QWaylandGLContext : public QPlatformGLContext {
public:
- QWaylandGLContext(EGLDisplay eglDisplay, const QPlatformWindowFormat &format);
+ QWaylandGLContext(EGLDisplay eglDisplay, const QSurfaceFormat &format, QPlatformGLContext *share);
~QWaylandGLContext();
- void makeCurrent();
+
+ void swapBuffers(QPlatformSurface *surface);
+
+ bool makeCurrent(QPlatformSurface *surface);
void doneCurrent();
- void swapBuffers();
- void* getProcAddress(const QString&);
- QPlatformWindowFormat platformWindowFormat() const { return mFormat; }
+ void (*getProcAddress(const QByteArray &procName)) ();
- void setEglSurface(EGLSurface surface);
- EGLConfig eglConfig() const;
-private:
- EGLDisplay mEglDisplay;
+ QSurfaceFormat format() const { return m_format; }
- EGLContext mContext;
- EGLSurface mSurface;
- EGLConfig mConfig;
- QPlatformWindowFormat mFormat;
+ EGLConfig eglConfig() const;
+ EGLContext eglContext() const { return m_context; }
- QWaylandGLContext();
+private:
+ EGLDisplay m_eglDisplay;
+ EGLContext m_context;
+ EGLConfig m_config;
+ QSurfaceFormat m_format;
};
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
index cd0701150f..8b4b163b03 100644
--- a/src/plugins/platforms/wayland/gl_integration/wayland_egl/wayland_egl.pri
+++ b/src/plugins/platforms/wayland/gl_integration/wayland_egl/wayland_egl.pri
@@ -1,5 +1,3 @@
-include (../../../eglconvenience/eglconvenience.pri)
-
LIBS += -lwayland-egl -lEGL
INCLUDEPATH += $$PWD
SOURCES += $$PWD/qwaylandeglintegration.cpp \