From 844204b2b04d0f3477d069db326f0e70129c71e2 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Wed, 7 Sep 2016 17:10:49 +0200 Subject: Refactor buffer handling We cannot support bindToTexture() functions. On some platforms the texture is provided by the driver. Therefore, the HW integration must always provide a texture. This has the added bonus of unifying the two separate code paths that were introduced when EGLStream support was added. Add a separate buffer manager that owns all buffers. Don't destroy buffer objects on release. The client will probably attach them again later. Also, release shm buffers immediately after uploading to texture (needs to be documented that image() will not work afterwards). Make the old SurfaceBuffer class into an abstract base class, so we can store state in the buffer class instead of having to map from the wl_resource in each buffer integration. Move the shared memory buffer handling into a separate subclass. Change-Id: I81e471d13c92913d31ea1efe487f93fa908b5e0c Reviewed-by: Dominik Holland Reviewed-by: Louai Al-Khanji Reviewed-by: Johan Helsing --- .../xcomposite-egl/xcompositeeglintegration.cpp | 50 ++++++++++++++++------ .../xcomposite-egl/xcompositeeglintegration.h | 28 +++++++++--- 2 files changed, 58 insertions(+), 20 deletions(-) (limited to 'src/hardwareintegration/compositor/xcomposite-egl') diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp index e858a8e78..1a478052b 100644 --- a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp +++ b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -83,23 +84,38 @@ void XCompositeEglClientBufferIntegration::initializeHardware(struct ::wl_displa } else { qFatal("Platform integration doesn't have native interface"); } - mScreen = XDefaultScreen(mDisplay); new XCompositeHandler(m_compositor, mDisplay); } -void XCompositeEglClientBufferIntegration::bindTextureToBuffer(struct ::wl_resource *buffer) +QtWayland::ClientBuffer *XCompositeEglClientBufferIntegration::createBufferFor(wl_resource *buffer) { - XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer); - Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window()); + if (wl_shm_buffer_get(buffer)) + return nullptr; + return new XCompositeEglClientBuffer(this, buffer); +} + + +XCompositeEglClientBuffer::XCompositeEglClientBuffer(XCompositeEglClientBufferIntegration *integration, wl_resource *bufferResource) + : QtWayland::ClientBuffer(bufferResource) + , m_texture(nullptr) + , m_integration(integration) +{ +} + +QOpenGLTexture *XCompositeEglClientBuffer::toOpenGlTexture(int plane) +{ + Q_UNUSED(plane); + XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(m_buffer); + Pixmap pixmap = XCompositeNameWindowPixmap(m_integration->xDisplay(), compositorBuffer->window()); QVector eglConfigSpec = eglbuildSpec(); EGLint matching = 0; EGLConfig config; - bool matched = eglChooseConfig(mEglDisplay,eglConfigSpec.constData(),&config,1,&matching); + bool matched = eglChooseConfig(m_integration->eglDisplay(),eglConfigSpec.constData(),&config,1,&matching); if (!matched || !matching) { qWarning("Could not retrieve a suitable EGL config"); - return; + return nullptr; } QVector attribList; @@ -110,29 +126,37 @@ void XCompositeEglClientBufferIntegration::bindTextureToBuffer(struct ::wl_resou attribList.append(EGL_TEXTURE_2D); attribList.append(EGL_NONE); - EGLSurface surface = eglCreatePixmapSurface(mEglDisplay,config,pixmap,attribList.constData()); + EGLSurface surface = eglCreatePixmapSurface(m_integration->eglDisplay(),config,pixmap,attribList.constData()); if (surface == EGL_NO_SURFACE) { qDebug() << "Failed to create eglsurface" << pixmap << compositorBuffer->window(); } compositorBuffer->setOrigin(QWaylandSurface::OriginTopLeft); - if (!eglBindTexImage(mEglDisplay,surface,EGL_BACK_BUFFER)) { - qDebug() << "Failed to bind"; + if (!m_texture) { + m_texture = new QOpenGLTexture(QOpenGLTexture::Target2D); + m_texture->create(); + } + m_texture->bind(); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + if (!eglBindTexImage(m_integration->eglDisplay(),surface,EGL_BACK_BUFFER)) { + qWarning() << "Failed to bind"; } // eglDestroySurface(mEglDisplay,surface); + return m_texture; } -QWaylandSurface::Origin XCompositeEglClientBufferIntegration::origin(struct ::wl_resource *buffer) const + +QWaylandSurface::Origin XCompositeEglClientBuffer::origin() const { - XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer); + XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(m_buffer); return compositorBuffer->origin(); } -QSize XCompositeEglClientBufferIntegration::bufferSize(struct ::wl_resource *buffer) const +QSize XCompositeEglClientBuffer::size() const { - XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer); + XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(m_buffer); return compositorBuffer->size(); } diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h index c14e582ed..ec4ea284b 100644 --- a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h +++ b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h @@ -40,7 +40,7 @@ #include #include - +#include #include "xlibinclude.h" #include @@ -53,16 +53,30 @@ public: XCompositeEglClientBufferIntegration(); void initializeHardware(struct ::wl_display *display) Q_DECL_OVERRIDE; - - void bindTextureToBuffer(struct ::wl_resource *buffer) Q_DECL_OVERRIDE; - QWaylandSurface::Origin origin(struct ::wl_resource *) const Q_DECL_OVERRIDE; - - QSize bufferSize(struct ::wl_resource *buffer) const Q_DECL_OVERRIDE; + QtWayland::ClientBuffer *createBufferFor(wl_resource *buffer) Q_DECL_OVERRIDE; + inline Display *xDisplay() const { return mDisplay; } + inline EGLDisplay eglDisplay() const { return mEglDisplay; } private: Display *mDisplay; EGLDisplay mEglDisplay; - int mScreen; +}; + +class XCompositeEglClientBuffer : public QtWayland::ClientBuffer +{ +public: + XCompositeEglClientBuffer(XCompositeEglClientBufferIntegration *integration, wl_resource *bufferResource); + + QSize size() const; + QWaylandSurface::Origin origin() const; + QOpenGLTexture *toOpenGlTexture(int plane) Q_DECL_OVERRIDE; + QWaylandBufferRef::BufferFormatEgl bufferFormatEgl() const Q_DECL_OVERRIDE { + return QWaylandBufferRef::BufferFormatEgl_RGBA; + } + +private: + QOpenGLTexture *m_texture; + XCompositeEglClientBufferIntegration *m_integration; }; QT_END_NAMESPACE -- cgit v1.2.3