#include <QPainter>
#include <QMouseEvent>
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
#include <QGLContext>
#include <QGLWidget>
-#include <GLES2/gl2.h>
#endif
#include <QDebug>
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
class QWidgetCompositor : public QGLWidget, public WaylandCompositor
#else
class QWidgetCompositor : public QWidget, public WaylandCompositor
QImage img = image(m_surfaces.at(i).first);
p.drawImage(m_surfaces.at(i).second.topLeft(), img);
}
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
else {
QPlatformGLContext *glcontext = platformWindow()->glContext();
if (glcontext) {
context->drawTexture(m_surfaces.at(i).second,textureId(m_surfaces.at(i).first));
}
}
-#endif //QT_COMPOSITOR_WAYLAND_EGL
+#endif //QT_COMPOSITOR_WAYLAND_GL
}
frameFinished();
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
//jl:FIX FIX FIX:)
update();
glFinish();
INCLUDEPATH += .
INCLUDEPATH += ../../src/qt-compositor/
-# comment out the following line to disable DRM
-CONFIG += wayland_egl
-
-wayland_egl {
- QT += opengl
-}
+# comment out the following CONFIG lines to disable DRM
+CONFIG += wayland_gl
+CONFIG += mesa_egl
DESTDIR=$$PWD/../../bin/
--- /dev/null
+/****************************************************************************
+**
+** This file is part of QtCompositor**
+**
+** Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation qt-info@nokia.com
+**
+** 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 Nokia Corporation 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.
+**
+****************************************************************************/
+
+#include "graphicshardwareintegration.h"
+
+GraphicsHardwareIntegration::GraphicsHardwareIntegration(WaylandCompositor *compositor)
+ : m_compositor(compositor)
+{
+}
--- /dev/null
+/****************************************************************************
+**
+** This file is part of QtCompositor**
+**
+** Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation qt-info@nokia.com
+**
+** 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 Nokia Corporation 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.
+**
+****************************************************************************/
+
+#ifndef GRAPHICSHARDWAREINTEGRATION_H
+#define GRAPHICSHARDWAREINTEGRATION_H
+
+#include <QtOpenGL/qgl.h>
+#include <wayland-server.h>
+
+#include "qtcompositor.h"
+
+class GraphicsHardwareIntegration
+{
+public:
+ GraphicsHardwareIntegration(WaylandCompositor *compositor);
+
+ virtual void intializeHardware(struct wl_display *waylandDisplay) = 0;
+
+ /** Bind the Wayland buffer to the textureId. The correct context is the current context,
+ so there is no need to do makeCurrent in this function.
+ **/
+ virtual void bindBufferToTexture(struct wl_buffer *buffer, GLuint textureId) = 0;
+
+protected:
+ WaylandCompositor *m_compositor;
+};
+
+#endif // GRAPHICSHARDWAREINTEGRATION_H
--- /dev/null
+/****************************************************************************
+**
+** This file is part of QtCompositor**
+**
+** Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation qt-info@nokia.com
+**
+** 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 Nokia Corporation 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.
+**
+****************************************************************************/
+
+#include "mesaeglintegration.h"
+
+#include <QtGui/QPlatformNativeInterface>
+#include <QtGui/private/qapplication_p.h>
+
+#define EGL_EGLEXT_PROTOTYPES
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#define GL_GLEXT_PROTOTYPES
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
+MesaEglIntegration::MesaEglIntegration(WaylandCompositor *compositor)
+ : GraphicsHardwareIntegration(compositor)
+{
+}
+
+void MesaEglIntegration::intializeHardware(wl_display *waylandDisplay)
+{
+ QPlatformNativeInterface *nativeInterface = QApplicationPrivate::platformIntegration()->nativeInterface();
+ if (nativeInterface) {
+ EGLDisplay m_egl_display = nativeInterface->nativeResourceForWidget("EglDisplay",0);
+ if (m_egl_display) {
+ eglBindWaylandDisplayWL(m_egl_display,waylandDisplay);
+ } else {
+ fprintf(stderr, "Failed to initialize egl display");
+ }
+ }
+}
+
+void MesaEglIntegration::bindBufferToTexture(wl_buffer *buffer, GLuint textureId)
+{
+ QPlatformNativeInterface *nativeInterface = QApplicationPrivate::platformIntegration()->nativeInterface();
+ EGLDisplay eglDisplay = static_cast<EGLDisplay>(nativeInterface->nativeResourceForWidget("EglDisplay",m_compositor->topLevelWidget()));
+ EGLContext eglContext = static_cast<EGLContext>(nativeInterface->nativeResourceForWidget("EglContext",m_compositor->topLevelWidget()));
+ Q_ASSERT(eglDisplay);
+ Q_ASSERT(eglContext);
+
+ EGLImageKHR image = eglCreateImageKHR(eglDisplay, eglContext,
+ EGL_WAYLAND_BUFFER_WL,
+ buffer, NULL);
+
+ glBindTexture(GL_TEXTURE_2D, textureId);
+
+ glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
+
+ eglDestroyImageKHR(eglDisplay, image);
+
+
+}
--- /dev/null
+/****************************************************************************
+**
+** This file is part of QtCompositor**
+**
+** Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation qt-info@nokia.com
+**
+** 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 Nokia Corporation 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.
+**
+****************************************************************************/
+
+#ifndef MESAEGLINTEGRATION_H
+#define MESAEGLINTEGRATION_H
+
+#include "../graphicshardwareintegration.h"
+
+class MesaEglIntegration : public GraphicsHardwareIntegration
+{
+public:
+ MesaEglIntegration(WaylandCompositor *compositor);
+
+ void intializeHardware(wl_display *waylandDisplay);
+
+ void bindBufferToTexture(wl_buffer *buffer, GLuint textureId);
+};
+
+#endif // MESAEGLINTEGRATION_H
#include <wayland-server.h>
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
-#include <private/qapplication_p.h>
-#include <QPlatformNativeInterface>
-#define EGL_EGLEXT_PROTOTYPES
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
+#ifdef QT_COMPOSITOR_MESA_EGL
+#include "../mesa_egl/mesaeglintegration.h"
#endif
namespace Wayland {
, m_last_queued_buf(-1)
, m_qt_compositor(qt_compositor)
{
+#ifdef QT_COMPOSITOR_MESA_EGL
+ m_graphics_hw_integration = new MesaEglIntegration(qt_compositor);
+#endif
if (wl_compositor_init(base(), &compositor_interface, m_display->handle())) {
fprintf(stderr, "Fatal: Error initializing compositor\n");
exit(EXIT_FAILURE);
}
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
- QPlatformNativeInterface *nativeInterface = QApplicationPrivate::platformIntegration()->nativeInterface();
- if (nativeInterface) {
- EGLDisplay m_egl_display = nativeInterface->nativeResourceForWidget("EglDisplay",0);
- if (m_egl_display) {
- eglBindWaylandDisplayWL(m_egl_display,m_display->handle());
- } else {
- fprintf(stderr, "Failed to initialize egl display");
- }
- }
-#endif //QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+ m_graphics_hw_integration->intializeHardware(m_display->handle());
+#endif //QT_COMPOSITOR_WAYLAND_GL
m_loop = wl_display_get_event_loop(m_display->handle());
return m_qt_compositor->topLevelWidget();
}
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+GraphicsHardwareIntegration * Compositor::gaphicsHWIntegration() const
+{
+ return m_graphics_hw_integration;
+}
+#endif
+
}
#include <wayland-server.h>
class WaylandCompositor;
+class GraphicsHardwareIntegration;
class QWidget;
namespace Wayland {
uint currentTimeMsecs() const;
QWidget *topLevelWidget() const;
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+ GraphicsHardwareIntegration *gaphicsHWIntegration() const;
+#endif
private slots:
void processWaylandEvents();
wl_event_loop *m_loop;
WaylandCompositor *m_qt_compositor;
+
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+ GraphicsHardwareIntegration *m_graphics_hw_integration;
+#endif
};
}
#include <wayland-server.h>
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
-#include <QtGui/QPlatformNativeInterface>
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+#include "../graphicshardwareintegration.cpp"
#include <QtGui/QPlatformGLContext>
-#define EGL_EGLEXT_PROTOTYPES
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
#endif
namespace Wayland {
{
current.type = State::Invalid;
staged.type = State::Invalid;
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
if (QWidget *topLevel = m_compositor->topLevelWidget()) {
if (topLevel->platformWindow() && topLevel->platformWindow()->glContext()) {
topLevel->platformWindow()->glContext()->makeCurrent();
BufferType type;
ShmBuffer *shm_buffer;
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
GLuint texture_id;
#endif
QRect rect;
if (buffer->attach) {
wayland_cast<Surface *>(surface)->attachShm(wayland_cast<ShmBuffer *>(buffer));
}
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
else {
- wayland_cast<Surface *>(surface)->attachEgl(buffer);
+ wayland_cast<Surface *>(surface)->attachHWBuffer(buffer);
}
#endif //QT_COMPOSITOR_WAYLAND_EGL
}
return QImage();
}
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
-void Surface::attachEgl(wl_buffer *egl_buffer)
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+
+void Surface::attachHWBuffer(struct wl_buffer *buffer)
{
Q_D(Surface);
- Q_ASSERT(d->m_compositor->topLevelWidget());
- QPlatformNativeInterface *nativeInterface = QApplicationPrivate::platformIntegration()->nativeInterface();
- Q_ASSERT(nativeInterface);
+ d->staged.type = SurfacePrivate::State::Texture;
+ d->current.type = d->staged.type;
+ d->current.texture_id = d->staged.texture_id;
//make current for the topLevel. We could have used the eglContext,
//but then we would need to handle eglSurfaces as well.
d->m_compositor->topLevelWidget()->platformWindow()->glContext()->makeCurrent();
- EGLDisplay eglDisplay = static_cast<EGLDisplay>(nativeInterface->nativeResourceForWidget("EglDisplay",d->m_compositor->topLevelWidget()));
- EGLContext eglContext = static_cast<EGLContext>(nativeInterface->nativeResourceForWidget("EglContext",d->m_compositor->topLevelWidget()));
- Q_ASSERT(eglDisplay);
- Q_ASSERT(eglContext);
-
- EGLImageKHR image = eglCreateImageKHR(eglDisplay, eglContext,
- EGL_WAYLAND_BUFFER_WL,
- egl_buffer, NULL);
-
- glBindTexture(GL_TEXTURE_2D, d->staged.texture_id);
-
- glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
-
- eglDestroyImageKHR(eglDisplay, image);
-
- d->staged.type = SurfacePrivate::State::Texture;
- d->current.type = d->staged.type;
- d->current.texture_id = d->staged.texture_id;
-
- d->m_compositor->surfaceResized(this,QSize(egl_buffer->width,egl_buffer->height));
+ d->m_compositor->gaphicsHWIntegration()->bindBufferToTexture(buffer,d->current.texture_id);
+ d->m_compositor->surfaceResized(this,QSize(buffer->width,buffer->height));
}
bool Surface::hasTexture() const
Q_D(const Surface);
return d->current.texture_id;
}
-#endif // QT_COMPOSITOR_WAYLAND_EGL
+#endif // QT_COMPOSITOR_WAYLAND_GL
void Surface::attachShm(Wayland::ShmBuffer *shm_buffer)
{
#include <QtCore/QMetaType>
#include <QtGui/private/qapplication_p.h>
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
#define GL_GLEXT_PROTOTYPES
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
~Surface();
uint id() const { return base()->resource.object.id; }
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
- void attachEgl(wl_buffer *egl_buffer);
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+ void attachHWBuffer(struct wl_buffer *buffer);
#endif
void attachShm(ShmBuffer *shm_buffer);
QImage image() const;
bool hasImage() const;
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
bool hasTexture() const;
GLuint textureId() const;
#endif
LIBS += -lwayland-server -lffi
-unix {
-# CONFIG += link_pkgconfig
-# PKGCONFIG += libdrm
+
+wayland_gl {
+ QT += opengl
+ DEFINES += QT_COMPOSITOR_WAYLAND_GL
+}
+
+mesa_egl {
+include (mesa_egl/mesa_egl.pri)
+DEFINES += QT_COMPOSITOR_MESA_EGL
}
SOURCES += $$PWD/qtcompositor.cpp \
+ $$PWD/graphicshardwareintegration.cpp \
$$PWD/private/wlcompositor.cpp \
$$PWD/private/wlsurface.cpp \
$$PWD/private/wloutput.cpp \
$$PWD/private/wldisplay.cpp \
- $$PWD/private/wlshmbuffer.cpp \
+ $$PWD/private/wlshmbuffer.cpp
HEADERS += $$PWD/qtcompositor.h \
+ $$PWD/graphicshardwareintegration.h \
$$PWD/private/wlcompositor.h \
$$PWD/private/wlsurface.h \
$$PWD/private/wloutput.h \
$$PWD/private/wlshmbuffer.h \
$$PWD/private/wldisplay.h \
- $$PWD/private/wlobject.h \
+ $$PWD/private/wlobject.h
INCLUDEPATH += $$PWD/../3rdparty/wayland
-
-wayland_egl {
- LIBS += -lEGL -lGLESv2
- DEFINES += QT_COMPOSITOR_WAYLAND_EGL
-}
return m_compositor->image(winId);
}
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
GLuint WaylandCompositor::textureId(uint winId) const
{
return m_compositor->getSurfaceFromWinId(winId)->textureId();
#include <QImage>
#include <QRect>
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
#define GL_GLEXT_PROTOTYPES
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
bool hasImage(uint winId) const;
const QImage image(uint winId) const;
-#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#ifdef QT_COMPOSITOR_WAYLAND_GL
bool hasTexture(uint winId) const;
GLuint textureId(uint winId) const;
#endif