diff options
author | Jorgen Lind <jorgen.lind@digia.com> | 2013-11-21 08:14:03 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-27 15:32:32 +0100 |
commit | eb1c91b2185df1d57a87ed2b5335f3b0ba500c67 (patch) | |
tree | f031559412f96061cbc41dfc791bb716c425203b /src/hardwareintegration/compositor/xcomposite-egl | |
parent | 83791e4c0104d8b87ad2f198f9c07407c45603e3 (diff) |
make compositor build with new directory layout
Change-Id: I3ede73420af9cb95820a9bec4fe7305f1107e22d
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
Diffstat (limited to 'src/hardwareintegration/compositor/xcomposite-egl')
3 files changed, 238 insertions, 0 deletions
diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcomposite-egl.pri b/src/hardwareintegration/compositor/xcomposite-egl/xcomposite-egl.pri new file mode 100644 index 000000000..cde790bdc --- /dev/null +++ b/src/hardwareintegration/compositor/xcomposite-egl/xcomposite-egl.pri @@ -0,0 +1,16 @@ +include($$PWD/../xcomposite_share/xcomposite_share.pri) + +!contains(QT_CONFIG, no-pkg-config) { + CONFIG += link_pkgconfig + PKGCONFIG += xcomposite egl x11 wayland-server +} else { + LIBS += -lXcomposite -lEGL -lX11 +} + +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/xcompositeeglintegration.h + +SOURCES += \ + $$PWD/xcompositeeglintegration.cpp diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp new file mode 100644 index 000000000..b80858b2c --- /dev/null +++ b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Compositor. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "xcompositeeglintegration.h" + +#include "wayland-xcomposite-server-protocol.h" + +#include <QtCompositor/private/qwlcompositor_p.h> +#include <QtGui/QGuiApplication> +#include <qpa/qplatformnativeinterface.h> +#include <qpa/qplatformopenglcontext.h> + +#include "xcompositebuffer.h" +#include "xcompositehandler.h" +#include <X11/extensions/Xcomposite.h> + +#include <QtCore/QDebug> + +QT_BEGIN_NAMESPACE + +QVector<EGLint> eglbuildSpec() +{ + QVector<EGLint> spec; + + spec.append(EGL_SURFACE_TYPE); spec.append(EGL_WINDOW_BIT | EGL_PIXMAP_BIT); + spec.append(EGL_RENDERABLE_TYPE); spec.append(EGL_OPENGL_ES2_BIT); + spec.append(EGL_BIND_TO_TEXTURE_RGBA); spec.append(EGL_TRUE); + spec.append(EGL_ALPHA_SIZE); spec.append(8); + spec.append(EGL_NONE); + return spec; +} + +XCompositeEglIntegration::XCompositeEglIntegration() + : QWaylandGraphicsHardwareIntegration() + , mDisplay(0) +{ + +} + +void XCompositeEglIntegration::initializeHardware(QtWayland::Display *) +{ + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + if (nativeInterface) { + mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForWindow("Display",m_compositor->window())); + if (!mDisplay) + qFatal("could not retireve Display from platform integration"); + mEglDisplay = static_cast<EGLDisplay>(nativeInterface->nativeResourceForWindow("EGLDisplay",m_compositor->window())); + if (!mEglDisplay) + qFatal("could not retrieve EGLDisplay from platform integration"); + } else { + qFatal("Platform integration doesn't have native interface"); + } + mScreen = XDefaultScreen(mDisplay); + new XCompositeHandler(m_compositor->handle(), mDisplay); +} + +GLuint XCompositeEglIntegration::createTextureFromBuffer(struct ::wl_resource *buffer, QOpenGLContext *) +{ + XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer); + Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window()); + + QVector<EGLint> eglConfigSpec = eglbuildSpec(); + + EGLint matching = 0; + EGLConfig config; + bool matched = eglChooseConfig(mEglDisplay,eglConfigSpec.constData(),&config,1,&matching); + if (!matched || !matching) { + qWarning("Could not retrieve a suitable EGL config"); + return 0; + } + + QVector<EGLint> attribList; + + attribList.append(EGL_TEXTURE_FORMAT); + attribList.append(EGL_TEXTURE_RGBA); + attribList.append(EGL_TEXTURE_TARGET); + attribList.append(EGL_TEXTURE_2D); + attribList.append(EGL_NONE); + + EGLSurface surface = eglCreatePixmapSurface(mEglDisplay,config,pixmap,attribList.constData()); + if (surface == EGL_NO_SURFACE) { + qDebug() << "Failed to create eglsurface" << pixmap << compositorBuffer->window(); + } + + compositorBuffer->setInvertedY(true); + + GLuint textureId; + glGenTextures(1,&textureId); + glBindTexture(GL_TEXTURE_2D, textureId); + + if (!eglBindTexImage(mEglDisplay,surface,EGL_BACK_BUFFER)) { + qDebug() << "Failed to bind"; + } + + // eglDestroySurface(mEglDisplay,surface); + + return textureId; +} + +bool XCompositeEglIntegration::isYInverted(struct ::wl_resource *buffer) const +{ + XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer); + return compositorBuffer->isYInverted(); +} + +QSize XCompositeEglIntegration::bufferSize(struct ::wl_resource *buffer) const +{ + XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer); + + return compositorBuffer->size(); +} + +QT_END_NAMESPACE diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h new file mode 100644 index 000000000..562fce140 --- /dev/null +++ b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Compositor. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XCOMPOSITEEGLINTEGRATION_H +#define XCOMPOSITEEGLINTEGRATION_H + +#include <QtCompositor/qwaylandgraphicshardwareintegration.h> + +#include "xlibinclude.h" + +#include <EGL/egl.h> + +QT_BEGIN_NAMESPACE + +class XCompositeEglIntegration : public QWaylandGraphicsHardwareIntegration +{ +public: + XCompositeEglIntegration(); + + void initializeHardware(QtWayland::Display *waylandDisplay) Q_DECL_OVERRIDE; + + GLuint createTextureFromBuffer(struct ::wl_resource *buffer, QOpenGLContext *context) Q_DECL_OVERRIDE; + bool isYInverted(struct ::wl_resource *) const Q_DECL_OVERRIDE; + + QSize bufferSize(struct ::wl_resource *buffer) const Q_DECL_OVERRIDE; + +private: + Display *mDisplay; + EGLDisplay mEglDisplay; + int mScreen; +}; + +QT_END_NAMESPACE + +#endif // XCOMPOSITEEGLINTEGRATION_H |