diff options
author | Jesse Barnes <jbarnes@virtuousgeek.org> | 2010-10-25 18:38:29 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2011-01-25 17:58:31 (GMT) |
commit | 4e417fd2d89c99184c939296d969a6fd312c9257 (patch) | |
tree | 91ccb1aa36d4e5da423f5c150cb0010c54b44a95 /src/plugins/platforms | |
parent | ca63274bd2e4def7b6b8c8daec978bb5e44faf6e (diff) | |
download | Qt-4e417fd2d89c99184c939296d969a6fd312c9257.zip Qt-4e417fd2d89c99184c939296d969a6fd312c9257.tar.gz Qt-4e417fd2d89c99184c939296d969a6fd312c9257.tar.bz2 |
Wayland: add partial GL widget support
GL widgets need a platform GL context. Add one to get hellogl_es2
limping along.
Diffstat (limited to 'src/plugins/platforms')
4 files changed, 56 insertions, 46 deletions
diff --git a/src/plugins/platforms/wayland/qwaylandintegration.cpp b/src/plugins/platforms/wayland/qwaylandintegration.cpp index c433983..9ac22e8 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.cpp +++ b/src/plugins/platforms/wayland/qwaylandintegration.cpp @@ -1,3 +1,7 @@ +#define GL_GLEXT_PROTOTYPES +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> + #include "qfontconfigdatabase.h" #include <QImageReader> @@ -434,6 +438,7 @@ QWaylandWindow::QWaylandWindow(QWidget *window, QWaylandDisplay *display) , mSurface(0) , mDisplay(display) , mGLContext(0) + , mBuffer(0) { static WId id = 1; @@ -451,6 +456,14 @@ WId QWaylandWindow::winId() const return mWindowId; } +void QWaylandWindow::setParent(const QPlatformWindow *parent) +{ + QWaylandWindow *wParent = (QWaylandWindow *)parent; + + mSurface = wParent->surface(); + wParent->attach(mBuffer); +} + void QWaylandWindow::setVisible(bool visible) { if (visible) { @@ -488,7 +501,7 @@ void QWaylandWindow::configure(uint32_t time, uint32_t edges, class QWaylandGLContext : public QPlatformGLContext { public: - QWaylandGLContext(QWaylandDisplay *wd, const QPlatformWindowFormat &format); + QWaylandGLContext(QWaylandDisplay *wd, QWaylandWindow *window, const QPlatformWindowFormat &format); ~QWaylandGLContext(); void makeCurrent(); void doneCurrent(); @@ -500,13 +513,16 @@ private: EGLContext mContext; QPlatformWindowFormat mFormat; QWaylandDisplay *mDisplay; + QWaylandWindow *mWindow; + GLuint mFbo, mRbo; }; -QWaylandGLContext::QWaylandGLContext(QWaylandDisplay *wd, const QPlatformWindowFormat &format) +QWaylandGLContext::QWaylandGLContext(QWaylandDisplay *wd, QWaylandWindow *window, const QPlatformWindowFormat &format) : QPlatformGLContext() , mContext(0) , mFormat(format) , mDisplay(wd) + , mWindow(window) { EGLDisplay eglDisplay; static const EGLint contextAttribs[] = { @@ -519,26 +535,50 @@ QWaylandGLContext::QWaylandGLContext(QWaylandDisplay *wd, const QPlatformWindowF mContext = eglCreateContext(eglDisplay, NULL, EGL_NO_CONTEXT, contextAttribs); eglMakeCurrent(eglDisplay, NULL, NULL, mContext); + + glGenFramebuffers(1, &mFbo); + glGenRenderbuffers(1, &mRbo); } QWaylandGLContext::~QWaylandGLContext() { if (mContext) eglDestroyContext(mDisplay->eglDisplay(), mContext); + glDeleteFramebuffers(1, &mFbo); + glDeleteRenderbuffers(1, &mRbo); } void QWaylandGLContext::makeCurrent() { + QWaylandDrmBuffer *mBuffer = (QWaylandDrmBuffer *)mWindow->getBuffer(); + QRect geometry = mWindow->geometry(); + eglMakeCurrent(mDisplay->eglDisplay(), 0, 0, mContext); + if (!mBuffer) + return; + glBindFramebuffer(GL_FRAMEBUFFER, mFbo); + glBindRenderbuffer(GL_RENDERBUFFER, mRbo); + glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, mBuffer->mImage); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_RENDERBUFFER, mRbo); } void QWaylandGLContext::doneCurrent() { + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindRenderbuffer(GL_RENDERBUFFER, 0); eglMakeCurrent(mDisplay->eglDisplay(), 0, 0, mContext); } void QWaylandGLContext::swapBuffers() { + QRect geometry = mWindow->geometry(); + + if (!mWindow->surface()) + return; + + wl_surface_damage(mWindow->surface(), 0, 0, + geometry.width(), geometry.height()); } void *QWaylandGLContext::getProcAddress(const QString &string) @@ -550,7 +590,7 @@ QPlatformGLContext *QWaylandWindow::glContext() const { if (!mGLContext) { QWaylandWindow *that = const_cast<QWaylandWindow *>(this); - that->mGLContext = new QWaylandGLContext(mDisplay, widget()->platformWindowFormat()); + that->mGLContext = new QWaylandGLContext(mDisplay, that, widget()->platformWindowFormat()); } return mGLContext; diff --git a/src/plugins/platforms/wayland/qwaylandintegration.h b/src/plugins/platforms/wayland/qwaylandintegration.h index 70fb538..e26f9e3 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.h +++ b/src/plugins/platforms/wayland/qwaylandintegration.h @@ -154,6 +154,7 @@ public: void configure(uint32_t time, uint32_t edges, int32_t x, int32_t y, int32_t width, int32_t height); WId winId() const; + void setParent(const QPlatformWindow *parent); QPlatformGLContext *glContext() const; void attach(QWaylandBuffer *buffer); QWaylandBuffer *getBuffer(void) { return mBuffer; } diff --git a/src/plugins/platforms/wayland/qwaylandwindowsurface.cpp b/src/plugins/platforms/wayland/qwaylandwindowsurface.cpp index 78900ba..6e7fa89 100644 --- a/src/plugins/platforms/wayland/qwaylandwindowsurface.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindowsurface.cpp @@ -155,13 +155,6 @@ public: QGLFormat format; mContext = new QGLContext(format, widget); mContext->create(); - glGenFramebuffers(1, &mFbo); - glGenRenderbuffers(1, &mRbo); - } - ~QWaylandPaintDevice() - { - glDeleteFramebuffers(1, &mFbo); - glDeleteRenderbuffers(1, &mRbo); } QSize size() const { return mWidget->size(); } @@ -174,25 +167,16 @@ private: QWaylandDisplay *mDisplay; QWidget *mWidget; QGLContext *mContext; - GLuint mFbo, mRbo; }; void QWaylandPaintDevice::beginPaint(void) { QWaylandWindow *mWindow = (QWaylandWindow *)mWidget->platformWindow(); - QWaylandDrmBuffer *mBuffer = (QWaylandDrmBuffer *)mWindow->getBuffer(); QPlatformGLContext *ctx = mWindow->glContext(); - QRect geometry = mWidget->geometry(); QGLPaintDevice::beginPaint(); ctx->makeCurrent(); - - glBindFramebuffer(GL_FRAMEBUFFER, mFbo); - glBindRenderbuffer(GL_RENDERBUFFER, mRbo); - glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, mBuffer->mImage); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_RENDERBUFFER, mRbo); } void QWaylandPaintDevice::endPaint(void) @@ -201,10 +185,6 @@ void QWaylandPaintDevice::endPaint(void) QPlatformGLContext *ctx = mWindow->glContext(); QRect geometry = mWidget->geometry(); - wl_surface_damage(mWindow->surface(), 0, 0, - geometry.width(), geometry.height()); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glBindRenderbuffer(GL_RENDERBUFFER, 0); ctx->doneCurrent(); QGLPaintDevice::endPaint(); @@ -272,30 +252,17 @@ QPaintDevice *QWaylandDrmWindowSurface::paintDevice() void QWaylandDrmWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) { - Q_UNUSED(region); Q_UNUSED(offset); - Q_UNUSED(widget); -#if 0 - GLuint surf_rbo, surf_fbo; - QWaylandWindow *mWindow = (QWaylandWindow *)widget->platformWindow(); - QPlatformGLContext *ctx = mWindow->glContext(); - QRect geometry = widget->geometry(); - - ctx->makeCurrent(); - - glGenFramebuffers(1, &surf_fbo); - glBindFramebuffer(GL_FRAMEBUFFER, surf_fbo); - glGenRenderbuffers(1, &surf_rbo); - glBindRenderbuffer(GL_RENDERBUFFER, surf_rbo); - glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, mBuffer->mImage); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_RENDERBUFFER, surf_rbo); - - wl_surface_damage(mWindow->surface(), 0, 0, - geometry.width(), geometry.height()); + QWaylandWindow *ww = (QWaylandWindow *) widget->platformWindow(); + QVector<QRect> rects = region.rects(); + const QRect *r; + int i; - ctx->doneCurrent(); -#endif + for (i = 0; i < rects.size(); i++) { + r = &rects.at(i); + wl_surface_damage(ww->surface(), + r->x(), r->y(), r->width(), r->height()); + } } void QWaylandDrmWindowSurface::resize(const QSize &size) diff --git a/src/plugins/platforms/wayland/wayland.pro b/src/plugins/platforms/wayland/wayland.pro index 7a3d0b9..ec3f9d3 100644 --- a/src/plugins/platforms/wayland/wayland.pro +++ b/src/plugins/platforms/wayland/wayland.pro @@ -11,7 +11,9 @@ SOURCES = main.cpp \ HEADERS = qwaylandintegration.h \ qwaylandwindowsurface.h -INCLUDEPATH += /usr/include/libdrm +contains(QT_CONFIG, opengl) { + QT += opengl +} LIBS += -lwayland-client -ldrm -lxkbcommon -lEGL -lGLESv2 include (../fontdatabases/fontconfig/fontconfig.pri) |