"cant move it around though :D" This is just to get something on screen.
Now we have to start doing this "proper". Trying to abstract some things
out etc :)
****************************************************************************/
#include "qtcompositor.h"
+
#include <QApplication>
#include <QWidget>
#include <QTimer>
#include <QPainter>
#include <QMouseEvent>
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#include <QGLContext>
+#include <QGLWidget>
+#include <GLES2/gl2.h>
+#endif
+
#include <QDebug>
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+class QWidgetCompositor : public QGLWidget, public WaylandCompositor
+#else
class QWidgetCompositor : public QWidget, public WaylandCompositor
+#endif
{
public:
- QWidgetCompositor() : WaylandCompositor(), m_dragging(false) {
+ QWidgetCompositor() : WaylandCompositor(this), m_dragging(false) {
setMouseTracking(true);
m_background = QImage(QLatin1String("background.jpg"));
//make sure we get the window id and create the glcontext
p.drawPixmap(rect(), m_backgroundScaled);
for (int i = 0; i < m_surfaces.size(); ++i) {
- QImage img = image(m_surfaces.at(i).first);
- p.drawImage(m_surfaces.at(i).second.topLeft(), img);
+ if (hasImage(m_surfaces.at(i).first)) {
+ QImage img = image(m_surfaces.at(i).first);
+ p.drawImage(m_surfaces.at(i).second.topLeft(), img);
+ }
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+ else {
+ QPlatformGLContext *glcontext = platformWindow()->glContext();
+ if (glcontext) {
+ QGLContext *context = QGLContext::fromPlatformGLContext(glcontext);
+ context->makeCurrent();
+ context->drawTexture(m_surfaces.at(i).second,textureId(m_surfaces.at(i).first));
+ }
+ }
+#endif //QT_COMPOSITOR_WAYLAND_EGL
}
frameFinished();
+
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+ //jl:FIX FIX FIX:)
+ update();
+ glFinish();
+#endif
}
void resizeEvent(QResizeEvent *)
INCLUDEPATH += ../../src/qt-compositor/
# comment out the following line to disable DRM
-CONFIG += wayland_drm
+CONFIG += wayland_egl
+
+wayland_egl {
+ QT += opengl
+}
DESTDIR=$$PWD/../../bin/
include (../../src/qt-compositor/qt-compositor.pri)
+LIBS += -L/home/jlind/install/lib
+INCLUDEPATH += /home/jlind/install/include
+
# Input
SOURCES += main.cpp
$$PWD/wlsurface.cpp \
$$PWD/wloutput.cpp \
$$PWD/wldisplay.cpp \
- $$PWD/wlbuffer.cpp \
$$PWD/wlshmbuffer.cpp
HEADERS += $$PWD/qtcompositor.h \
$$PWD/wlcompositor.h \
$$PWD/wlsurface.h \
$$PWD/wloutput.h \
- $$PWD/wlbuffer.h \
$$PWD/wlshmbuffer.h \
$$PWD/wldisplay.h \
$$PWD/wlobject.h
INCLUDEPATH += $$PWD/../3rdparty/wayland
-wayland_drm {
- SOURCES += $$PWD/wldrmbuffer.cpp
- HEADERS += $$PWD/wldrmbuffer.h
-
- DEFINES += QT_WAYLAND_DRM
- LIBS += -lxcb-dri2 -lEGL
+wayland_egl {
+ LIBS += -lEGL -lGLESv2
+ DEFINES += QT_COMPOSITOR_WAYLAND_EGL
}
#include "qtcompositor.h"
#include "wlcompositor.h"
+#include "wlsurface.h"
-WaylandCompositor::WaylandCompositor()
+WaylandCompositor::WaylandCompositor(QWidget *topLevelWidget)
: m_compositor(new Wayland::Compositor(this))
+ , m_toplevel_widget(topLevelWidget)
{
}
return 0;
}
+bool WaylandCompositor::hasImage(uint winId) const
+{
+ return m_compositor->getSurfaceFromWinId(winId)->hasImage();
+}
+
const QImage WaylandCompositor::image(uint winId) const
{
return m_compositor->image(winId);
}
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+GLuint WaylandCompositor::textureId(uint winId) const
+{
+ return m_compositor->getSurfaceFromWinId(winId)->textureId();
+}
+
+bool WaylandCompositor::hasTexture(uint winId) const
+{
+ return m_compositor->getSurfaceFromWinId(winId)->hasTexture();
+}
+#endif
+
+QWidget * WaylandCompositor::topLevelWidget() const
+{
+ return m_toplevel_widget;
+}
+
#include <QImage>
#include <QRect>
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#define GL_GLEXT_PROTOTYPES
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#endif
+
+class QWidget;
+
namespace Wayland
{
class Compositor;
class WaylandCompositor
{
public:
- WaylandCompositor();
+ WaylandCompositor(QWidget *topLevelWidget = 0);
virtual ~WaylandCompositor();
void sendMousePressEvent(uint winId, int x, int y, Qt::MouseButton button);
void setDirectRenderWinId(uint winId);
uint directRenderWinId() const;
+ QWidget *topLevelWidget()const;
+
+ bool hasImage(uint winId) const;
const QImage image(uint winId) const;
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+ bool hasTexture(uint winId) const;
+ GLuint textureId(uint winId) const;
+#endif
+
virtual void surfaceCreated(uint winId) = 0;
virtual void surfaceDestroyed(uint winId) = 0;
virtual void surfaceMapped(uint winId, const QRect &rect) = 0;
private:
Wayland::Compositor *m_compositor;
+ QWidget *m_toplevel_widget;
+
};
#endif // QTCOMP_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 "wlbuffer.h"
-
-#include "wlcompositor.h"
-
-namespace Wayland {
-
-void attachBuffer(struct wl_buffer *buffer, struct wl_surface *surface){
- wayland_cast<Buffer *>(buffer)->attach(wayland_cast<Surface *>(surface));
-}
-
-void damageBuffer(struct wl_buffer *buffer,
- struct wl_surface *surface,
- int32_t x, int32_t y, int32_t width, int32_t height)
-{
- wayland_cast<Buffer *>(buffer)->damage(wayland_cast<Surface *>(surface), QRect(x, y, width, height));
-}
-
-Buffer::Buffer(Compositor *compositor, struct wl_visual *visual, const QSize &size)
-{
- base()->visual = visual;
- base()->compositor = compositor->base();
- base()->width = size.width();
- base()->height = size.height();
- base()->attach = attachBuffer;
- base()->damage = damageBuffer;
-}
-
-QSize Buffer::size() const
-{
- return QSize(base()->width,base()->height);
-}
-
-}
+++ /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 WLBUFFER_H
-#define WLBUFFER_H
-
-#include "wlobject.h"
-#include <wayland-server.h>
-
-#include <QtCore/QSize>
-#include <QtCore/QRect>
-
-namespace Wayland {
-
-class Compositor;
-class Surface;
-class Buffer : public Object<struct wl_buffer>
-{
-public:
- enum BufferType {
- Shm,
- Egl
- };
-
- Buffer(Compositor *compositor, struct wl_visual *visual, const QSize &size);
-
- QSize size()const;
- virtual BufferType type() const = 0;
-
- virtual void attach(Surface *surface) =0;
- virtual void damage(Surface *surface, const QRect &rect) =0;
-
-};
-
-}
-#endif // WLBUFFER_H
#include "wlobject.h"
#include "wldisplay.h"
#include "wlshmbuffer.h"
+#include "wlsurface.h"
#include "qtcompositor.h"
#include <QApplication>
#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>
+#endif
namespace Wayland {
Compositor::Compositor(WaylandCompositor *qt_compositor)
: m_display(new Display)
, m_shm(this)
-#ifdef QT_WAYLAND_DRM
- , m_drm(this)
-#endif
, m_current_frame(0)
, m_last_queued_buf(-1)
, m_qt_compositor(qt_compositor)
m_display->addGlobalObject(m_output.base(), &wl_output_interface, 0, output_post_geometry);
m_display->addGlobalObject(&m_shell, &wl_shell_interface, &shell_interface, 0);
-#ifdef QT_WAYLAND_DRM
- m_display->addGlobalObject(m_drm.base(), &wl_drm_interface, &drm_interface, post_drm_device);
-#endif
m_display->addGlobalObject(m_shm.base(), &wl_shm_interface, &shm_interface, 0);
wl_input_device_init(&m_input, base());
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
+
m_loop = wl_display_get_event_loop(m_display->handle());
int fd = wl_event_loop_get_fd(m_loop);
}
}
+QWidget * Compositor::topLevelWidget() const
+{
+ return m_qt_compositor->topLevelWidget();
}
+
+}
+
#define WL_COMPOSITOR_H
#include "wloutput.h"
-#include "wlsurface.h"
#include "wldisplay.h"
#include "wlshmbuffer.h"
-#ifdef QT_WAYLAND_DRM
-# include "wldrmbuffer.h"
-#endif
#include <wayland-server.h>
class WaylandCompositor;
+class QWidget;
namespace Wayland {
+class Surface;
+
class Compositor : public QObject, public Object<struct wl_compositor>
{
Q_OBJECT
struct wl_client *getClientFromWinId(uint winId) const;
QImage image(uint winId) const;
+
const struct wl_input_device *inputDevice() const { return &m_input; }
struct wl_input_device *inputDevice() { return &m_input; }
uint currentTimeMsecs() const;
+ QWidget *topLevelWidget() const;
+
private slots:
void processWaylandEvents();
struct wl_object m_shell;
- /* shm/drm-Handler */
+ /* shm/*/
ShmHandler m_shm;
-#ifdef QT_WAYLAND_DRM
- DrmHandler m_drm;
-#endif
QList<Surface *> m_surfaces;
/* Render state */
+++ /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 "wldrmbuffer.h"
-
-#include "wlcompositor.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include <QtGui/private/qapplication_p.h>
-#include <QtGui/QPlatformNativeInterface>
-#include <QtCore/QDebug>
-
-#include <xcb/dri2.h>
-#include <xcb/xfixes.h>
-#include <X11/Xlib.h>
-
-#define GL_GLEXT_PROTOTYPES
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-
-extern "C" {
-#include <xf86drm.h>
-}
-
-namespace Wayland {
-
-DrmBuffer::DrmBuffer(EGLImageKHR image, Compositor *compositor, struct wl_visual *visual, const QSize &size)
- : Buffer(compositor,visual,size)
- , m_image(image)
-{
-
-}
-
-void DrmBuffer::attach(Surface *surface)
-{
- Q_UNUSED(surface);
- printf("drmBuffer::attach\n");
-}
-
-void DrmBuffer::damage(Surface *surface, const QRect &rect)
-{
- Q_UNUSED(surface);
- Q_UNUSED(rect);
- printf("drmBuffer::damage\n");
-
-}
-
-
-void authenticate(struct wl_client *client,
- struct wl_drm *drm,
- uint32_t id)
-{
- qDebug() << "authenticate";
- Q_UNUSED(client);
- wl_object *object = (wl_object*)drm;
- DrmHandler *handler = wayland_cast<DrmHandler *>(object);
- handler->authenticate(id);
- wl_client_post_event(client, object, WL_DRM_AUTHENTICATED);
-}
-
-void create_buffer(struct wl_client *client,
- struct wl_drm *drm,
- uint32_t id,
- uint32_t name,
- int width,
- int height,
- uint32_t stride,
- struct wl_visual *visual)
-{
- wl_object *object = (wl_object*)drm;
- DrmHandler *handler = wayland_cast<DrmHandler *>(object);
- handler->createBuffer(client,id,name,QSize(width,height),stride,visual);
-}
-
-void post_drm_device(struct wl_client *client, struct wl_object *global)
-{
- //Lighthouse apis needs to bleed this, think I need to create a native interface abstraction
- wl_client_post_event(client, global, WL_DRM_DEVICE,"/dev/dri/card0");
-}
-
-DrmHandler::DrmHandler(Compositor *compositor)
- :m_compositor(compositor)
-{
- QPlatformNativeInterface *nativeInterface = QApplicationPrivate::platformIntegration()->nativeInterface();
- m_connection = static_cast<xcb_connection_t *>(nativeInterface->nativeResourceForWidget("Connection",0));
- xcb_screen_t *screen = static_cast<xcb_screen_t *>(nativeInterface->nativeResourceForWidget("Screen",0));
- m_root_window = screen->root;
- m_egl_display = static_cast<EGLDisplay>(nativeInterface->nativeResourceForWidget("EglDisplay",0));
-
- initializeDrm();
-}
-
-void DrmHandler::initializeDrm()
-{
-}
-
-void DrmHandler::authenticate(uint32_t id)
-{
- xcb_dri2_authenticate_cookie_t authenticateCoockie = xcb_dri2_authenticate_unchecked(m_connection,m_root_window,id);
- xcb_dri2_authenticate_reply_t *authenticate = xcb_dri2_authenticate_reply(m_connection,authenticateCoockie,NULL);
-
- if (!authenticate || !authenticate->authenticated) {
- fprintf(stderr,"Failed to authenticate drm :(\n");
- }
-
- free(authenticate);
-}
-
-void DrmHandler::createBuffer(wl_client *client, uint32_t id, uint32_t name, const QSize &size, uint32_t stride, wl_visual *visual)
-{
- EGLImageKHR image;
- EGLint attribs[] = {
- EGL_WIDTH, size.width(),
- EGL_HEIGHT, size.height(),
- EGL_DRM_BUFFER_STRIDE_MESA, stride /4,
- EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
- EGL_NONE
- };
-
- image = eglCreateImageKHR(m_egl_display,
- EGL_NO_CONTEXT,
- EGL_DRM_BUFFER_MESA,
- (EGLClientBuffer) name, attribs);
-
- DrmBuffer *buffer = new DrmBuffer(image,m_compositor,visual,size);
-
- addClientResource(client,&buffer->base()->resource,id,&wl_buffer_interface,&drm_interface,0);
-}
-
-}
+++ /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 WL_DRMBUFFER_H
-#define WL_DRMBUFFER_H
-
-#include "wlbuffer.h"
-
-#include <QtGui/QPlatformIntegration>
-
-#include <wayland-server.h>
-
-#include <xcb/xcb.h>
-
-#define MESA_EGL_NO_X11_HEADERS
-#define EGL_EGLEXT_PROTOTYPES
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-
-//class Display;
-
-namespace Wayland {
-
-class Compositor;
-struct Display;
-class DrmBuffer : public Buffer
-{
-public:
- DrmBuffer(EGLImageKHR image, Compositor *compositor, struct wl_visual *visual, const QSize &size);
-
- Buffer::BufferType type() const {return Buffer::Egl;}
-
- void attach(Surface *surface);
- void damage(Surface *surface, const QRect &rect);
-
-private:
- EGLImageKHR m_image;
-};
-
-class DrmHandler : public Object<struct wl_object>
-{
-public:
- DrmHandler(Compositor *compositor);
- void initializeDrm();
-
- void authenticate(uint32_t id);
- void createBuffer(struct wl_client *client, uint32_t id, uint32_t name,
- const QSize &size, uint32_t stride, struct wl_visual *visual);
-private:
-
- xcb_connection_t *m_connection;
- xcb_window_t m_root_window;
- EGLDisplay m_egl_display;
-
- Compositor *m_compositor;
-};
-
-void authenticate(struct wl_client *client,
- struct wl_drm *drm,
- uint32_t id);
-void create_buffer(struct wl_client *client,
- struct wl_drm *drm,
- uint32_t id,
- uint32_t name,
- int width,
- int height,
- uint32_t stride,
- struct wl_visual *visual);
-
-void post_drm_device(struct wl_client *client, struct wl_object *global);
-
-const struct wl_drm_interface drm_interface = {
- authenticate,
- create_buffer
-};
-
-
-}
-
-#endif // WL_DRMBUFFER_H
void shm_buffer_attach(struct wl_buffer *buffer, struct wl_surface *surface)
{
- wayland_cast<ShmBuffer *>(buffer)->attach(wayland_cast<Surface *>(surface));
+ wayland_cast<ShmBuffer *>(buffer)->attach(reinterpret_cast<Surface *>(surface));
}
void shm_buffer_damage(struct wl_buffer *buffer, struct wl_surface *surface, int x, int y, int width, int height)
{
- wayland_cast<ShmBuffer *>(buffer)->damage(wayland_cast<Surface *>(surface), QRect(x, y, width, height));
+ wayland_cast<ShmBuffer *>(buffer)->damage(reinterpret_cast<Surface *>(surface), QRect(x, y, width, height));
}
-
void shm_buffer_destroy(struct wl_resource *resource, struct wl_client *)
{
delete wayland_cast<ShmBuffer *>((wl_buffer *)resource);
const QSize &size,
uint stride,
struct wl_visual *visual)
- : Buffer(compositor,visual,size)
{
+ base()->compositor = reinterpret_cast<wl_compositor *>(compositor);
+ base()->height = size.height();
+ base()->width = size.width();
+ base()->visual = visual;
+ base()->attach = shm_buffer_attach;
+ base()->damage = shm_buffer_damage;
m_stride = stride;
m_data = mmap(NULL, stride * size.height(), PROT_READ, MAP_SHARED, fd, 0);
close(fd);
#ifndef WL_SHMBUFFER_H
#define WL_SHMBUFFER_H
-#include "wlbuffer.h"
-#include "wlsurface.h"
+#include "wlobject.h"
#include <QtCore/QRect>
#include <QtGui/QImage>
+
+
namespace Wayland {
-struct Surface;
-class ShmBuffer : public Buffer
+class Surface;
+class Compositor;
+
+class ShmBuffer : public Object<struct wl_buffer>
{
public:
ShmBuffer(int fd,
void attach(Surface *surface);
void damage(Surface *surface, const QRect &rect);
- Buffer::BufferType type() const {return Buffer::Shm;}
-
QImage image() const;
QSize size() const;
#include "wlcompositor.h"
#include "wlshmbuffer.h"
+
#include <QtCore/QDebug>
+#include <wayland-server.h>
+
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#include <QtGui/QPlatformNativeInterface>
+#include <QtGui/QPlatformGLContext>
+#define EGL_EGLEXT_PROTOTYPES
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#endif
+
namespace Wayland {
+class SurfacePrivate
+{
+public:
+ SurfacePrivate(struct wl_client *client, Compositor *compositor)
+ : m_client(client)
+ , m_compositor(compositor)
+ {
+ current.type = State::Invalid;
+ staged.type = State::Invalid;
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+ if (QWidget *topLevel = m_compositor->topLevelWidget()) {
+ if (topLevel->platformWindow() && topLevel->platformWindow()->glContext()) {
+ topLevel->platformWindow()->glContext()->makeCurrent();
+ glGenTextures(1,¤t.texture_id);
+ staged.texture_id = current.texture_id;
+ }
+ }
+#endif
+ }
+
+ struct State {
+ enum BufferType {
+ Shm,
+ Texture,
+ Invalid
+ };
+
+ BufferType type;
+
+ ShmBuffer *shm_buffer;
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+ GLuint texture_id;
+#endif
+ QRect rect;
+
+ };
+
+ State current;
+ State staged;
+
+ struct wl_client *m_client;
+ Compositor *m_compositor;
+};
+
+
+
void surface_destroy(struct wl_client *client, struct wl_surface *surface)
{
wl_resource_destroy(&surface->resource, client);
Q_UNUSED(x);
Q_UNUSED(y);
- wayland_cast<Surface *>(surface)->attach(wayland_cast<ShmBuffer *>(buffer));
+ if (buffer->attach) {
+ wayland_cast<Surface *>(surface)->attachShm(wayland_cast<ShmBuffer *>(buffer));
+ }
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+ else {
+ wayland_cast<Surface *>(surface)->attachEgl(buffer);
+ }
+#endif //QT_COMPOSITOR_WAYLAND_EGL
}
void surface_map_toplevel(struct wl_client *client,
}
Surface::Surface(struct wl_client *client, Compositor *compositor)
- : m_client(client)
- , m_compositor(compositor)
+ : d_ptr(new SurfacePrivate(client,compositor))
{
base()->client = client;
wl_list_init(&base()->destroy_listener_list);
-
- current.buffer = 0;
- staged.buffer = 0;
}
Surface::~Surface()
{
- m_compositor->surfaceDestroyed(this);
+ Q_D(Surface);
+ d->m_compositor->surfaceDestroyed(this);
}
-
void Surface::damage(const QRect &rect)
{
- m_compositor->surfaceDamaged(this, rect);
+ Q_D(Surface);
+ d->m_compositor->surfaceDamaged(this, rect);
+}
+
+bool Surface::hasImage() const
+{
+ Q_D(const Surface);
+ return d->current.type == SurfacePrivate::State::Shm;
}
QImage Surface::image() const
{
- if (current.buffer && current.buffer->type() == Buffer::Shm) {
- return static_cast<ShmBuffer *>(current.buffer)->image();
+ Q_D(const Surface);
+ if (d->current.type == SurfacePrivate::State::Shm) {
+ return d->current.shm_buffer->image();
}
return QImage();
}
-void Surface::attach(Buffer *buffer)
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+void Surface::attachEgl(wl_buffer *egl_buffer)
+{
+ Q_D(Surface);
+ Q_ASSERT(d->m_compositor->topLevelWidget());
+ QPlatformNativeInterface *nativeInterface = QApplicationPrivate::platformIntegration()->nativeInterface();
+ Q_ASSERT(nativeInterface);
+
+ //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));
+}
+
+bool Surface::hasTexture() const
+{
+ Q_D(const Surface);
+ return (d->current.type == SurfacePrivate::State::Texture);
+}
+
+GLuint Surface::textureId() const
+{
+ Q_D(const Surface);
+ return d->current.texture_id;
+}
+#endif // QT_COMPOSITOR_WAYLAND_EGL
+
+void Surface::attachShm(Wayland::ShmBuffer *shm_buffer)
+{
+ Q_D(Surface);
+ d->current.shm_buffer = d->current.shm_buffer = shm_buffer;
+ d->current.type = d->staged.type = SurfacePrivate::State::Shm;
+ d->m_compositor->surfaceResized(this, shm_buffer->size());
+}
+
+
+void Surface::mapTopLevel()
+{
+ Q_D(Surface);
+ d->staged.rect = QRect(0, 0, 200, 200);
+}
+
+void Surface::commit()
{
- current.buffer = staged.buffer = buffer;
- m_compositor->surfaceResized(this, buffer->size());
+ Q_D(Surface);
+ d->current = d->staged;
+ d->m_compositor->surfaceResized(this, buffer->size());
}
}
#define WL_SURFACE_H
#include "wlobject.h"
+#include "wlshmbuffer.h"
#include <QtCore/QRect>
#include <QtGui/QImage>
+#include <QtCore/QTextStream>
+#include <QtCore/QMetaType>
+#include <QtGui/private/qapplication_p.h>
+
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+#define GL_GLEXT_PROTOTYPES
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#endif
+
namespace Wayland {
class Compositor;
class Buffer;
+
+class SurfacePrivate;
+
class Surface : public Object<struct wl_surface>
{
+ Q_DECLARE_PRIVATE(Surface)
public:
Surface(struct wl_client *client, Compositor *compositor);
~Surface();
- struct State {
- Buffer *buffer;
- QRect rect;
- };
-
uint id() const { return base()->resource.object.id; }
- void attach(Buffer *buffer);
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+ void attachEgl(wl_buffer *egl_buffer);
+#endif
+ void attachShm(ShmBuffer *shm_buffer);
- void mapTopLevel() { staged.rect = QRect(0, 0, 200, 200); }
+ void mapTopLevel();
- void commit() { current = staged; }
+ void commit();
void damage(const QRect &rect);
QImage image() const;
+ bool hasImage() const;
-private:
- State current;
- State staged;
+#ifdef QT_COMPOSITOR_WAYLAND_EGL
+ bool hasTexture() const;
+ GLuint textureId() const;
+#endif
- struct wl_client *m_client;
- Compositor *m_compositor;
+protected:
+ QScopedPointer<SurfacePrivate> d_ptr;
+private:
+ Q_DISABLE_COPY(Surface)
};
void surface_destroy(struct wl_client *client, struct wl_surface *_surface);