Add XComposite extension to wayland
authorJørgen Lind <jorgen.lind@nokia.com>
Wed, 6 Apr 2011 08:10:12 +0000 (10:10 +0200)
committerJørgen Lind <jorgen.lind@nokia.com>
Wed, 6 Apr 2011 09:05:53 +0000 (11:05 +0200)
20 files changed:
examples/qwidget-compositor/qt-compositor.pro
src/qt-compositor/compositor_api/waylandcompositor.cpp
src/qt-compositor/compositor_api/waylandcompositor.h
src/qt-compositor/hardware_integration/hardware_integration.pri
src/qt-compositor/hardware_integration/xcomposite_glx/xcomposite_glx.pri [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.h [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_share/protocol/wayland-xcomposite.xml [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_share/wayland-xcomposite-client-protocol.h [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_share/wayland-xcomposite-protocol.c [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_share/wayland-xcomposite-server-protocol.h [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_share/xcomposite_share.pri [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_share/xcompositebuffer.cpp [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_share/xcompositebuffer.h [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_share/xcompositehandler.cpp [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_share/xcompositehandler.h [new file with mode: 0644]
src/qt-compositor/hardware_integration/xcomposite_share/xlibinclude.h [new file with mode: 0644]
src/qt-compositor/wayland_wrapper/wlcompositor.cpp
src/qt-compositor/wayland_wrapper/wlcompositor.h
src/qt-compositor/wayland_wrapper/wlsurface.h

index 7add9c1..b31c02e 100644 (file)
@@ -7,14 +7,13 @@ INCLUDEPATH += .
 #CONFIG += wayland_gl
 #CONFIG += mesa_egl
 #CONFIG += dri2_xcb
+#CONFIG += xcomposite_glx
 
 # comment out the following to not use pkg-config in the pri files
 CONFIG += use_pkgconfig
 
 DESTDIR=$$PWD/../../bin/
 
-QT += opengl
-
 include (../../src/qt-compositor/qt-compositor.pri)
 
 # Input
index cbe49ff..b9c9355 100644 (file)
@@ -56,6 +56,7 @@ WaylandCompositor::WaylandCompositor(QWidget *topLevelWidget)
     qmlRegisterType<WaylandSurfaceItem>("WaylandCompositor", 1, 0, "WaylandSurfaceItem");
     qRegisterMetaType<WaylandSurface*>("WaylandSurface*");
 #endif
+    m_compositor->initializeHardwareIntegration();
 }
 
 WaylandCompositor::~WaylandCompositor()
index 8e2a2ea..20b136f 100644 (file)
@@ -46,9 +46,7 @@
 #include <QRect>
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-#define GL_GLEXT_PROTOTYPES
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
+#include <QtOpenGL/QGLContext>
 #endif
 
 class QWidget;
index 22cd0fe..381c428 100644 (file)
@@ -4,14 +4,24 @@ HEADERS += \
 SOURCES += \
     $$PWD/graphicshardwareintegration.cpp
 
-wayland_gl {
-    mesa_egl {
-        include (mesa_egl/mesa_egl.pri)
-        DEFINES += QT_COMPOSITOR_MESA_EGL
-    }
+wayland_gl{
+    contains(QT_CONFIG, opengl) {
+        DEFINES += QT_WAYLAND_GL_SUPPORT
+        QT += opengl
 
-    dri2_xcb {
-        include (dri2_xcb/dri2_xcb.pri)
-        DEFINES += QT_COMPOSITOR_DRI2_XCB
+        contains(QT_CONFIG, opengles2) {
+            mesa_egl {
+                include (mesa_egl/mesa_egl.pri)
+                DEFINES += QT_COMPOSITOR_MESA_EGL
+            }
+            dri2_xcb {
+                include (dri2_xcb/dri2_xcb.pri)
+                DEFINES += QT_COMPOSITOR_DRI2_XCB
+            }
+        } else {
+            xcomposite_glx {
+                include (xcomposite_glx/xcomposite_glx.pri)
+            }
+        }
     }
 }
diff --git a/src/qt-compositor/hardware_integration/xcomposite_glx/xcomposite_glx.pri b/src/qt-compositor/hardware_integration/xcomposite_glx/xcomposite_glx.pri
new file mode 100644 (file)
index 0000000..8881916
--- /dev/null
@@ -0,0 +1,9 @@
+include (../xcomposite_share/xcomposite_share.pri)
+
+LIBS += -lXcomposite
+
+HEADERS += \
+    $$PWD/xcompositeglxintegration.h
+
+SOURCES += \
+    $$PWD/xcompositeglxintegration.cpp
diff --git a/src/qt-compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp b/src/qt-compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.cpp
new file mode 100644 (file)
index 0000000..383fa65
--- /dev/null
@@ -0,0 +1,100 @@
+#include "xcompositeglxintegration.h"
+
+#include "waylandobject.h"
+#include "wayland_wrapper/wlcompositor.h"
+#include "wayland-xcomposite-server-protocol.h"
+
+#include <QtGui/QPlatformNativeInterface>
+#include <QtGui/QPlatformGLContext>
+#include <private/qapplication_p.h>
+
+#include "xcompositebuffer.h"
+#include "xcompositehandler.h"
+#include <X11/extensions/Xcomposite.h>
+
+#include <QtCore/QDebug>
+
+QVector<int> qglx_buildSpec()
+{
+    QVector<int> spec(48);
+    int i = 0;
+
+    spec[i++] = GLX_LEVEL;
+    spec[i++] = 0;
+    spec[i++] = GLX_DRAWABLE_TYPE; spec[i++] = GLX_PIXMAP_BIT;
+    spec[i++] = GLX_BIND_TO_TEXTURE_TARGETS_EXT; spec[i++] = GLX_TEXTURE_2D_BIT_EXT;
+    spec[i++] = GLX_BIND_TO_TEXTURE_RGB_EXT; spec[i++] = TRUE;
+
+    spec[i++] = 0;
+    return spec;
+}
+
+
+struct wl_xcomposite_interface XCompositeHandler::xcomposite_interface = {
+    XCompositeHandler::create_buffer
+};
+
+GraphicsHardwareIntegration *GraphicsHardwareIntegration::createGraphicsHardwareIntegration(WaylandCompositor *compositor)
+{
+    return new XCompositeGLXIntegration(compositor);
+}
+
+XCompositeGLXIntegration::XCompositeGLXIntegration(WaylandCompositor *compositor)
+    : GraphicsHardwareIntegration(compositor)
+    , mDisplay(0)
+{
+    QPlatformNativeInterface *nativeInterface = QApplicationPrivate::platformIntegration()->nativeInterface();
+    if (nativeInterface) {
+        mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForWidget("Display",m_compositor->topLevelWidget()));
+        if (!mDisplay)
+            qFatal("could not retireve Display from platform integration");
+    } else {
+        qFatal("Platform integration doesn't have native interface");
+    }
+    mScreen = XDefaultScreen(mDisplay);
+}
+
+void XCompositeGLXIntegration::initializeHardware(Wayland::Display *waylandDisplay)
+{
+    XCompositeHandler *handler = new XCompositeHandler(m_compositor->handle(),mDisplay,m_compositor->topLevelWidget());
+    waylandDisplay->addGlobalObject(handler->base(), &wl_xcomposite_interface, &XCompositeHandler::xcomposite_interface,XCompositeHandler::send_root_information);
+
+    QPlatformGLContext *glContext = m_compositor->topLevelWidget()->platformWindow()->glContext();
+
+    m_glxBindTexImageEXT = reinterpret_cast<PFNGLXBINDTEXIMAGEEXTPROC>(glContext->getProcAddress("glXBindTexImageEXT"));
+    if (!m_glxBindTexImageEXT) {
+        qDebug() << "Did not find glxBindTexImageExt, everything will FAIL!";
+    }
+    m_glxReleaseTexImageEXT = reinterpret_cast<PFNGLXRELEASETEXIMAGEEXTPROC>(glContext->getProcAddress("glXReleaseTexImageEXT"));
+    if (!m_glxReleaseTexImageEXT) {
+        qDebug() << "Did not find glxReleaseTexImageExt";
+    }
+}
+
+GLuint XCompositeGLXIntegration::createTextureFromBuffer(wl_buffer *buffer)
+{
+    XCompositeBuffer *compositorBuffer = Wayland::wayland_cast<XCompositeBuffer *>(buffer);
+    Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window());
+
+    QVector<int> glxConfigSpec = qglx_buildSpec();
+    int numberOfConfigs;
+    GLXFBConfig *configs = glXChooseFBConfig(mDisplay,mScreen,glxConfigSpec.constData(),&numberOfConfigs);
+
+    QVector<int> attribList;
+    attribList.append(GLX_TEXTURE_FORMAT_EXT);
+    attribList.append(GLX_TEXTURE_FORMAT_RGB_EXT);
+    attribList.append(GLX_TEXTURE_TARGET_EXT);
+    attribList.append(GLX_TEXTURE_2D_EXT);
+    attribList.append(0);
+    GLXPixmap glxPixmap = glXCreatePixmap(mDisplay,*configs,pixmap,attribList.constData());
+    XFree(configs);
+
+    GLuint textureId;
+    glGenTextures(1,&textureId);
+    glBindTexture(GL_TEXTURE_2D, textureId);
+    m_glxBindTexImageEXT(mDisplay,glxPixmap,GLX_FRONT_EXT, 0);
+    //Do we need to change the api so that we do bind and release in the painevent?
+    //The specification states that when deleting the texture the color buffer is deleted
+//    m_glxReleaseTexImageEXT(mDisplay,glxPixmap,GLX_FRONT_EXT);
+    return textureId;
+}
diff --git a/src/qt-compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.h b/src/qt-compositor/hardware_integration/xcomposite_glx/xcompositeglxintegration.h
new file mode 100644 (file)
index 0000000..c11adb6
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef XCOMPOSITEGLXINTEGRATION_H
+#define XCOMPOSITEGLXINTEGRATION_H
+
+#include "hardware_integration/graphicshardwareintegration.h"
+
+#include "xlibinclude.h"
+
+#define GLX_GLXEXT_PROTOTYPES
+#include <GL/glx.h>
+#include <GL/glxext.h>
+
+class XCompositeGLXIntegration : public GraphicsHardwareIntegration
+{
+public:
+    XCompositeGLXIntegration(WaylandCompositor *compositor);
+
+    void initializeHardware(Wayland::Display *waylandDisplay);
+
+    GLuint createTextureFromBuffer(struct wl_buffer *buffer);
+
+private:
+    PFNGLXBINDTEXIMAGEEXTPROC m_glxBindTexImageEXT;
+    PFNGLXRELEASETEXIMAGEEXTPROC m_glxReleaseTexImageEXT;
+
+    Display *mDisplay;
+    int mScreen;
+};
+
+#endif // XCOMPOSITEGLXINTEGRATION_H
diff --git a/src/qt-compositor/hardware_integration/xcomposite_share/protocol/wayland-xcomposite.xml b/src/qt-compositor/hardware_integration/xcomposite_share/protocol/wayland-xcomposite.xml
new file mode 100644 (file)
index 0000000..1bef458
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="xcomposite">
+  <!-- XComposite support. This object is created by the server and published
+       using the display's global event. -->
+  <interface name="xcomposite" version="1">
+
+    <!-- Create a wayland buffer for X Window. -->
+    <request name="create_buffer">
+      <arg name="id" type="new_id" interface="buffer"/>
+      <arg name="x_window" type="uint"/>
+      <arg name="width" type="int"/>
+      <arg name="height" type="int"/>
+      <arg name="visual" type="object" interface="visual"/>
+    </request>
+
+    <!-- Notification of the root window to use for the X Window created
+         on the client side. Also passes in the Display name to use -->
+    <event name="root">
+      <arg name="display_name" type="string"/>
+      <arg name="root_window" type="uint"/>
+    </event>
+
+  </interface>
+
+</protocol>
diff --git a/src/qt-compositor/hardware_integration/xcomposite_share/wayland-xcomposite-client-protocol.h b/src/qt-compositor/hardware_integration/xcomposite_share/wayland-xcomposite-client-protocol.h
new file mode 100644 (file)
index 0000000..1955a74
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2010 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+
+#ifndef XCOMPOSITE_CLIENT_PROTOCOL_H
+#define XCOMPOSITE_CLIENT_PROTOCOL_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stddef.h>
+#include "wayland-util.h"
+
+struct wl_client;
+
+struct wl_xcomposite;
+
+struct wl_proxy;
+
+extern void
+wl_proxy_marshal(struct wl_proxy *p, uint32_t opcode, ...);
+extern struct wl_proxy *
+wl_proxy_create(struct wl_proxy *factory,
+               const struct wl_interface *interface);
+extern struct wl_proxy *
+wl_proxy_create_for_id(struct wl_display *display,
+                      const struct wl_interface *interface, uint32_t id);
+extern void
+wl_proxy_destroy(struct wl_proxy *proxy);
+
+extern int
+wl_proxy_add_listener(struct wl_proxy *proxy,
+                     void (**implementation)(void), void *data);
+
+extern void
+wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
+
+extern void *
+wl_proxy_get_user_data(struct wl_proxy *proxy);
+
+extern const struct wl_interface wl_xcomposite_interface;
+
+struct wl_xcomposite_listener {
+       void (*root)(void *data,
+                    struct wl_xcomposite *xcomposite,
+                    const char *display_name,
+                    uint32_t root_window);
+};
+
+static inline int
+wl_xcomposite_add_listener(struct wl_xcomposite *xcomposite,
+                          const struct wl_xcomposite_listener *listener, void *data)
+{
+       return wl_proxy_add_listener((struct wl_proxy *) xcomposite,
+                                    (void (**)(void)) listener, data);
+}
+
+#define WL_XCOMPOSITE_CREATE_BUFFER    0
+
+static inline struct wl_xcomposite *
+wl_xcomposite_create(struct wl_display *display, uint32_t id)
+{
+       return (struct wl_xcomposite *)
+               wl_proxy_create_for_id(display, &wl_xcomposite_interface, id);
+}
+
+static inline void
+wl_xcomposite_set_user_data(struct wl_xcomposite *xcomposite, void *user_data)
+{
+       wl_proxy_set_user_data((struct wl_proxy *) xcomposite, user_data);
+}
+
+static inline void *
+wl_xcomposite_get_user_data(struct wl_xcomposite *xcomposite)
+{
+       return wl_proxy_get_user_data((struct wl_proxy *) xcomposite);
+}
+
+static inline void
+wl_xcomposite_destroy(struct wl_xcomposite *xcomposite)
+{
+       wl_proxy_destroy((struct wl_proxy *) xcomposite);
+}
+
+static inline struct wl_buffer *
+wl_xcomposite_create_buffer(struct wl_xcomposite *xcomposite, uint32_t x_window, int width, int height, struct wl_visual *visual)
+{
+       struct wl_proxy *id;
+
+       id = wl_proxy_create((struct wl_proxy *) xcomposite,
+                            &wl_buffer_interface);
+       if (!id)
+               return NULL;
+
+       wl_proxy_marshal((struct wl_proxy *) xcomposite,
+                        WL_XCOMPOSITE_CREATE_BUFFER, id, x_window, width, height, visual);
+
+       return (struct wl_buffer *) id;
+}
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/qt-compositor/hardware_integration/xcomposite_share/wayland-xcomposite-protocol.c b/src/qt-compositor/hardware_integration/xcomposite_share/wayland-xcomposite-protocol.c
new file mode 100644 (file)
index 0000000..da2e4a2
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright © 2010 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+
+#include <stdlib.h>
+#include <stdint.h>
+#include "wayland-util.h"
+
+static const struct wl_message xcomposite_requests[] = {
+       { "create_buffer", "nuiio" },
+};
+
+static const struct wl_message xcomposite_events[] = {
+       { "root", "su" },
+};
+
+WL_EXPORT const struct wl_interface wl_xcomposite_interface = {
+       "xcomposite", 1,
+       ARRAY_LENGTH(xcomposite_requests), xcomposite_requests,
+       ARRAY_LENGTH(xcomposite_events), xcomposite_events,
+};
+
diff --git a/src/qt-compositor/hardware_integration/xcomposite_share/wayland-xcomposite-server-protocol.h b/src/qt-compositor/hardware_integration/xcomposite_share/wayland-xcomposite-server-protocol.h
new file mode 100644 (file)
index 0000000..6902c74
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2010 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+
+#ifndef XCOMPOSITE_SERVER_PROTOCOL_H
+#define XCOMPOSITE_SERVER_PROTOCOL_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stddef.h>
+#include "wayland-util.h"
+
+struct wl_client;
+
+struct wl_xcomposite;
+
+extern const struct wl_interface wl_xcomposite_interface;
+
+struct wl_xcomposite_interface {
+       void (*create_buffer)(struct wl_client *client,
+                             struct wl_xcomposite *xcomposite,
+                             uint32_t id,
+                             uint32_t x_window,
+                             int width,
+                             int height,
+                             struct wl_visual *visual);
+};
+
+#define WL_XCOMPOSITE_ROOT     0
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/qt-compositor/hardware_integration/xcomposite_share/xcomposite_share.pri b/src/qt-compositor/hardware_integration/xcomposite_share/xcomposite_share.pri
new file mode 100644 (file)
index 0000000..31faa90
--- /dev/null
@@ -0,0 +1,12 @@
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+    $$PWD/wayland-xcomposite-server-protocol.h \
+    $$PWD/xcompositebuffer.h \
+    $$PWD/xcompositehandler.h \
+    $$PWD/xlibinclude.h
+
+SOURCES += \
+    $$PWD/wayland-xcomposite-protocol.c \
+    $$PWD/xcompositebuffer.cpp \
+    $$PWD/xcompositehandler.cpp
diff --git a/src/qt-compositor/hardware_integration/xcomposite_share/xcompositebuffer.cpp b/src/qt-compositor/hardware_integration/xcomposite_share/xcompositebuffer.cpp
new file mode 100644 (file)
index 0000000..892b93e
--- /dev/null
@@ -0,0 +1,34 @@
+#include "xcompositebuffer.h"
+
+XCompositeBuffer::XCompositeBuffer(Wayland::Compositor *compositor, Window window, const QSize &size, struct wl_visual *visual)
+    : mWindow(window)
+{
+    base()->attach = 0;
+    base()->damage = 0;
+    base()->compositor = compositor->base();
+    base()->height = size.height();
+    base()->width = size.width();
+    base()->visual = visual;
+}
+
+struct wl_buffer_interface XCompositeBuffer::buffer_interface = {
+    XCompositeBuffer::buffer_interface_destroy
+};
+
+void XCompositeBuffer::buffer_interface_destroy(wl_client *client, wl_buffer *buffer)
+{
+    Q_UNUSED(client);
+    Q_UNUSED(buffer);
+}
+
+void XCompositeBuffer::delete_resource(struct wl_resource *resource,
+                                    struct wl_client *client)
+{
+    Q_UNUSED(client);
+    delete reinterpret_cast<XCompositeBuffer *>(resource);
+}
+
+Window XCompositeBuffer::window()
+{
+    return mWindow;
+}
diff --git a/src/qt-compositor/hardware_integration/xcomposite_share/xcompositebuffer.h b/src/qt-compositor/hardware_integration/xcomposite_share/xcompositebuffer.h
new file mode 100644 (file)
index 0000000..2b847d0
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef XCOMPOSITEBUFFER_H
+#define XCOMPOSITEBUFFER_H
+
+#include "waylandobject.h"
+#include "wayland_wrapper/wlcompositor.h"
+
+#include <QtCore/QSize>
+
+#include <QtCore/QTextStream>
+#include <QtCore/QDataStream>
+#include <QtCore/QMetaType>
+#include <QtCore/QVariant>
+#include <QtGui/QWidget>
+
+#include <X11/X.h>
+
+class XCompositeBuffer : public Wayland::Object<struct wl_buffer>
+{
+public:
+    XCompositeBuffer(Wayland::Compositor *compositor, Window window, const QSize &size, struct wl_visual *visual);
+
+    Window window();
+
+    static struct wl_buffer_interface buffer_interface;
+    static void delete_resource(struct wl_resource *resource,
+                                        struct wl_client *client);
+private:
+    Window mWindow;
+
+    static void buffer_interface_destroy(struct wl_client *client,
+                        struct wl_buffer *buffer);
+};
+
+#endif // XCOMPOSITORBUFFER_H
diff --git a/src/qt-compositor/hardware_integration/xcomposite_share/xcompositehandler.cpp b/src/qt-compositor/hardware_integration/xcomposite_share/xcompositehandler.cpp
new file mode 100644 (file)
index 0000000..1860e76
--- /dev/null
@@ -0,0 +1,51 @@
+#include "xcompositehandler.h"
+
+#include "wayland-xcomposite-server-protocol.h"
+
+#include "xcompositebuffer.h"
+#include <X11/extensions/Xcomposite.h>
+
+XCompositeHandler::XCompositeHandler(Wayland::Compositor *compositor, Display *display, QWidget *topLevelWidget)
+    : mCompositor(compositor)
+    , mTopLevelWidget(topLevelWidget)
+    , mDisplay(display)
+{
+    mFakeRootWidget = new QWidget(mCompositor->topLevelWidget());
+    mFakeRootWidget->setGeometry(-1,-1,1,1);
+    mFakeRootWidget->setAttribute(Qt::WA_NativeWindow);
+    int composite_event_base, composite_error_base;
+    if (XCompositeQueryExtension(mDisplay, &composite_event_base, &composite_error_base)) {
+
+    } else {
+        qFatal("XComposite required");
+    }
+}
+
+void XCompositeHandler::createBuffer(struct wl_client *client, uint32_t id, Window window, const QSize &size, struct wl_visual *visual)
+{
+    XCompositeBuffer *buffer = new XCompositeBuffer(mCompositor, window, size, visual);
+    Wayland::addClientResource(client,&buffer->base()->resource,
+                               id,&wl_buffer_interface,
+                               &XCompositeBuffer::buffer_interface,
+                               XCompositeBuffer::delete_resource);
+}
+
+void XCompositeHandler::send_root_information(struct wl_client *client, struct wl_object *global)
+{
+    XCompositeHandler *handler = Wayland::wayland_cast<XCompositeHandler *>(global);
+    const char *displayString = XDisplayString(handler->mDisplay);
+    wl_client_post_event(client, global, WL_XCOMPOSITE_ROOT, displayString, handler->mFakeRootWidget->winId());
+}
+
+void XCompositeHandler::create_buffer(struct wl_client *client,
+                      struct wl_xcomposite *xcomposite,
+                      uint32_t id,
+                      uint32_t x_window,
+                      int width,
+                      int height,
+                      struct wl_visual *visual)
+{
+    Window window = (Window)x_window;
+    XCompositeHandler *that = reinterpret_cast<XCompositeHandler *>(xcomposite);
+    that->createBuffer(client, id, window, QSize(width,height),visual);
+}
diff --git a/src/qt-compositor/hardware_integration/xcomposite_share/xcompositehandler.h b/src/qt-compositor/hardware_integration/xcomposite_share/xcompositehandler.h
new file mode 100644 (file)
index 0000000..0a72896
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef XCOMPOSITEHANDLER_H
+#define XCOMPOSITEHANDLER_H
+
+#include "wayland_wrapper/wlcompositor.h"
+
+#include "xlibinclude.h"
+
+class XCompositeHandler : public Wayland::Object<struct wl_object>
+{
+public:
+    XCompositeHandler(Wayland::Compositor *compositor, Display *display, QWidget *topLevelWidget);
+    void createBuffer(struct wl_client *client, uint32_t id, Window window, const QSize &size, struct wl_visual *visual);
+
+    static void send_root_information(struct wl_client *client, struct wl_object *global);
+    static struct wl_xcomposite_interface xcomposite_interface;
+
+private:
+    Wayland::Compositor *mCompositor;
+    QWidget *mTopLevelWidget;
+    QWidget *mFakeRootWidget;
+    Display *mDisplay;
+
+    static void create_buffer(struct wl_client *client,
+                          struct wl_xcomposite *xcomposite,
+                          uint32_t id,
+                          uint32_t x_window,
+                          int width,
+                          int height,
+                          struct wl_visual *visual);
+
+};
+
+#endif // XCOMPOSITEHANDLER_H
diff --git a/src/qt-compositor/hardware_integration/xcomposite_share/xlibinclude.h b/src/qt-compositor/hardware_integration/xcomposite_share/xlibinclude.h
new file mode 100644 (file)
index 0000000..2e67fba
--- /dev/null
@@ -0,0 +1,8 @@
+#include <QtCore/QEvent>
+#include <QtCore/QTextStream>
+#include <QtCore/QDataStream>
+#include <QtCore/QMetaType>
+#include <QtCore/QVariant>
+#include <QtGui/QCursor>
+
+#include <X11/Xlib.h>
index ab152e8..17da9a7 100644 (file)
@@ -195,10 +195,6 @@ Compositor::Compositor(WaylandCompositor *qt_compositor)
         exit(EXIT_FAILURE);
     }
 
-#ifdef QT_COMPOSITOR_WAYLAND_GL
-    m_graphics_hw_integration->initializeHardware(m_display);
-#endif //QT_COMPOSITOR_WAYLAND_GL
-
     m_loop = wl_display_get_event_loop(m_display->handle());
 
     int fd = wl_event_loop_get_fd(m_loop);
@@ -325,12 +321,22 @@ QWidget * Compositor::topLevelWidget() const
     return m_qt_compositor->topLevelWidget();
 }
 
-#ifdef QT_COMPOSITOR_WAYLAND_GL
 GraphicsHardwareIntegration * Compositor::graphicsHWIntegration() const
 {
+#ifdef QT_COMPOSITOR_WAYLAND_GL
     return m_graphics_hw_integration;
+#else
+    return 0;
+#endif
 }
+
+void Compositor::initializeHardwareIntegration()
+{
+#ifdef QT_COMPOSITOR_WAYLAND_GL
+    m_graphics_hw_integration->initializeHardware(m_display);
 #endif
+}
+
 
 }
 
index 481ac09..29ad455 100644 (file)
@@ -83,9 +83,9 @@ public:
     uint currentTimeMsecs() const;
 
     QWidget *topLevelWidget() const;
-#ifdef QT_COMPOSITOR_WAYLAND_GL
+
     GraphicsHardwareIntegration *graphicsHWIntegration() const;
-#endif
+    void initializeHardwareIntegration();
 
     wl_input_device *defaultInputDevice();
 private slots:
index 17877e9..1d4e590 100644 (file)
@@ -53,9 +53,7 @@
 #include <QtGui/private/qapplication_p.h>
 
 #ifdef QT_COMPOSITOR_WAYLAND_GL
-#define GL_GLEXT_PROTOTYPES
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
+#include <QtOpenGL/QGLContext>
 #endif
 
 namespace Wayland {