summaryrefslogtreecommitdiffstats
path: root/examples/wayland/server-buffer/compositor
diff options
context:
space:
mode:
Diffstat (limited to 'examples/wayland/server-buffer/compositor')
-rw-r--r--examples/wayland/server-buffer/compositor/compositor.pro23
-rw-r--r--examples/wayland/server-buffer/compositor/compositor.qrc7
-rw-r--r--examples/wayland/server-buffer/compositor/images/background.jpgbin0 -> 30730 bytes
-rw-r--r--examples/wayland/server-buffer/compositor/main.cpp268
-rw-r--r--examples/wayland/server-buffer/compositor/qml/ServerBufferContainer.qml75
-rw-r--r--examples/wayland/server-buffer/compositor/qml/main.qml83
-rw-r--r--examples/wayland/server-buffer/compositor/serverbufferitem.cpp126
-rw-r--r--examples/wayland/server-buffer/compositor/serverbufferitem.h99
-rw-r--r--examples/wayland/server-buffer/compositor/serverbuffertextureprovider.h77
9 files changed, 758 insertions, 0 deletions
diff --git a/examples/wayland/server-buffer/compositor/compositor.pro b/examples/wayland/server-buffer/compositor/compositor.pro
new file mode 100644
index 000000000..9f7751a09
--- /dev/null
+++ b/examples/wayland/server-buffer/compositor/compositor.pro
@@ -0,0 +1,23 @@
+QT += core-private gui-private quick-private compositor-private
+
+LIBS += -lwayland-server
+
+SOURCES += \
+ main.cpp \
+ serverbufferitem.cpp
+HEADERS += \
+ serverbufferitem.h \
+
+OTHER_FILES = \
+ qml/main.qml \
+ images/background.jpg \
+
+RESOURCES += compositor.qrc
+
+CONFIG +=wayland-scanner
+WAYLANDSERVERSOURCES += ../share-buffer.xml
+
+CONFIG += link_pkgconfig
+PKGCONFIG += wayland-server
+
+DEFINES += QT_COMPOSITOR_QUICK
diff --git a/examples/wayland/server-buffer/compositor/compositor.qrc b/examples/wayland/server-buffer/compositor/compositor.qrc
new file mode 100644
index 000000000..dbbbfb1cf
--- /dev/null
+++ b/examples/wayland/server-buffer/compositor/compositor.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file>images/background.jpg</file>
+ <file>qml/main.qml</file>
+ <file>qml/ServerBufferContainer.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/wayland/server-buffer/compositor/images/background.jpg b/examples/wayland/server-buffer/compositor/images/background.jpg
new file mode 100644
index 000000000..445567fbd
--- /dev/null
+++ b/examples/wayland/server-buffer/compositor/images/background.jpg
Binary files differ
diff --git a/examples/wayland/server-buffer/compositor/main.cpp b/examples/wayland/server-buffer/compositor/main.cpp
new file mode 100644
index 000000000..9f86539fd
--- /dev/null
+++ b/examples/wayland/server-buffer/compositor/main.cpp
@@ -0,0 +1,268 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $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 "qwaylandquickcompositor.h"
+#include "qwaylandsurface.h"
+#include "qwaylandsurfaceitem.h"
+
+#include <QGuiApplication>
+#include <QTimer>
+#include <QPainter>
+#include <QMouseEvent>
+#include <QOpenGLContext>
+
+#include <QQmlContext>
+
+#include <QQuickItem>
+#include <QQuickView>
+
+#include "qwayland-server-share-buffer.h"
+#include <QtCompositor/private/qwlcompositor_p.h>
+#include <QtCompositor/private/qwlserverbufferintegration_p.h>
+
+#include "serverbufferitem.h"
+
+#include <QtGui/private/qdistancefield_p.h>
+
+class QmlCompositor
+ : public QQuickView
+ , public QWaylandQuickCompositor
+ , public QtWaylandServer::qt_share_buffer
+{
+ Q_OBJECT
+
+public:
+ QmlCompositor()
+ : QWaylandQuickCompositor(this, 0, DefaultExtensions | SubSurfaceExtension)
+ , QtWaylandServer::qt_share_buffer(QWaylandCompositor::handle()->wl_display(), 1)
+ , m_server_buffer_32_bit(0)
+ , m_server_buffer_item_32_bit(0)
+ , m_server_buffer_8_bit(0)
+ , m_server_buffer_item_8_bit(0)
+ {
+ setSource(QUrl("qrc:/qml/main.qml"));
+ setResizeMode(QQuickView::SizeRootObjectToView);
+ setColor(Qt::black);
+ create();
+ grabWindow();
+ addDefaultShell();
+
+ connect(this, SIGNAL(afterRendering()), this, SLOT(sendCallbacks()));
+
+ connect(this, SIGNAL(sceneGraphInitialized()), this, SLOT(initiateServerBuffer()),Qt::DirectConnection);
+ connect(this, SIGNAL(serverBuffersCreated()), this, SLOT(createServerBufferItems()));
+ }
+
+ Q_INVOKABLE QWaylandSurfaceItem *item(QWaylandSurface *surf)
+ {
+ return static_cast<QWaylandSurfaceItem *>(surf->views().first());
+ }
+
+signals:
+ void windowAdded(QVariant window);
+ void windowDestroyed(QVariant window);
+ void windowResized(QVariant window);
+ void serverBufferItemCreated(QVariant);
+ void serverBuffersCreated();
+
+public slots:
+ void destroyClientForWindow(QVariant window)
+ {
+ QWaylandSurface *surface = qobject_cast<QWaylandSurface *>(qvariant_cast<QObject *>(window));
+ destroyClientForSurface(surface);
+ }
+
+private slots:
+ void surfaceMapped() {
+ QWaylandSurface *surface = qobject_cast<QWaylandSurface *>(sender());
+ emit windowAdded(QVariant::fromValue(surface));
+ }
+
+ void surfaceUnmapped() {
+ QWaylandSurface *surface = qobject_cast<QWaylandSurface *>(sender());
+ emit windowDestroyed(QVariant::fromValue(surface));
+ }
+
+ void surfaceDestroyed(QObject *object) {
+ QWaylandSurface *surface = static_cast<QWaylandSurface *>(object);
+ emit windowDestroyed(QVariant::fromValue(surface));
+ }
+
+ void sendCallbacks() {
+ sendFrameCallbacks(surfaces());
+ }
+
+ void initiateServerBuffer()
+ {
+ if (!QWaylandCompositor::handle()->serverBufferIntegration())
+ return;
+
+ openglContext()->makeCurrent(this);
+
+ QtWayland::ServerBufferIntegration *sbi = QWaylandCompositor::handle()->serverBufferIntegration();
+ if (!sbi) {
+ qWarning("Could not find a Server Buffer Integration");
+ return;
+ }
+ if (sbi->supportsFormat(QtWayland::ServerBuffer::RGBA32)) {
+ QImage image(100,100,QImage::Format_ARGB32_Premultiplied);
+ image.fill(QColor(0x55,0x0,0x55,0x01));
+ {
+ QPainter p(&image);
+ QPen pen = p.pen();
+ pen.setWidthF(3);
+ pen.setColor(Qt::red);
+ p.setPen(pen);
+ p.drawLine(0,0,100,100);
+ pen.setColor(Qt::green);
+ p.setPen(pen);
+ p.drawLine(100,0,0,100);
+ pen.setColor(Qt::blue);
+ p.setPen(pen);
+ p.drawLine(25,15,75,15);
+ }
+ image = image.convertToFormat(QImage::Format_RGBA8888);
+
+ m_server_buffer_32_bit = sbi->createServerBuffer(image.size(),QtWayland::ServerBuffer::RGBA32);
+
+ GLuint texture_32_bit;
+ glGenTextures(1, &texture_32_bit);
+ glBindTexture(GL_TEXTURE_2D, texture_32_bit);
+ m_server_buffer_32_bit->bindTextureToBuffer();
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image.width(), image.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.constBits());
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glDeleteTextures(1, &texture_32_bit);
+
+ }
+
+ if (sbi->supportsFormat(QtWayland::ServerBuffer::A8)) {
+ QRawFont defaultRaw = QRawFont::fromFont(QFont(), QFontDatabase::Latin);
+ QVector<quint32> index = defaultRaw.glyphIndexesForString(QStringLiteral("R"));
+ QDistanceField distanceField(defaultRaw, index.front(), true);
+ QImage img = distanceField.toImage(QImage::Format_Indexed8);
+
+ m_server_buffer_8_bit = sbi->createServerBuffer(img.size(), QtWayland::ServerBuffer::A8);
+ GLuint texture_8_bit;
+ glGenTextures(1, &texture_8_bit);
+ glBindTexture(GL_TEXTURE_2D, texture_8_bit);
+ m_server_buffer_8_bit->bindTextureToBuffer();
+
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, img.width(), img.height(), GL_ALPHA, GL_UNSIGNED_BYTE, img.constBits());
+ }
+ emit serverBuffersCreated();
+ }
+
+ void createServerBufferItems()
+ {
+ if (m_server_buffer_32_bit) {
+ m_server_buffer_item_32_bit = new ServerBufferItem(m_server_buffer_32_bit);
+ m_server_buffer_item_32_bit->setUseTextureAlpha(true);
+ emit serverBufferItemCreated(QVariant::fromValue(m_server_buffer_item_32_bit));
+ }
+ if (m_server_buffer_8_bit) {
+ m_server_buffer_item_8_bit = new ServerBufferItem(m_server_buffer_8_bit);
+ m_server_buffer_item_8_bit->setUseTextureAlpha(true);
+ emit serverBufferItemCreated(QVariant::fromValue(m_server_buffer_item_8_bit));
+ }
+ }
+protected:
+ void resizeEvent(QResizeEvent *event)
+ {
+ QQuickView::resizeEvent(event);
+ QWaylandCompositor::setOutputGeometry(QRect(0, 0, width(), height()));
+ }
+
+ void surfaceCreated(QWaylandSurface *surface) {
+ connect(surface, SIGNAL(mapped()), this, SLOT(surfaceMapped()));
+ connect(surface,SIGNAL(unmapped()), this,SLOT(surfaceUnmapped()));
+ }
+
+ void share_buffer_bind_resource(Resource *resource) Q_DECL_OVERRIDE
+ {
+ if (m_server_buffer_32_bit) {
+ struct ::wl_client *client = resource->handle->client;
+ struct ::wl_resource *buffer = m_server_buffer_32_bit->resourceForClient(client);
+ send_cross_buffer(resource->handle, buffer);
+
+ }
+ if (m_server_buffer_8_bit) {
+ struct ::wl_client *client = resource->handle->client;
+ struct ::wl_resource *buffer = m_server_buffer_8_bit->resourceForClient(client);
+ send_cross_buffer(resource->handle, buffer);
+
+ }
+ }
+
+private:
+ QtWayland::ServerBuffer *m_server_buffer_32_bit;
+ ServerBufferItem *m_server_buffer_item_32_bit;
+ QtWayland::ServerBuffer *m_server_buffer_8_bit;
+ ServerBufferItem *m_server_buffer_item_8_bit;
+};
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ if (!app.arguments().contains(QStringLiteral("--invert"))) {
+ qDebug() << "iverting";
+ qputenv("QT_COMPOSITOR_NEGATE_INVERTED_Y", "1");
+ }
+
+ qmlRegisterType<ServerBufferItem>();
+
+ QmlCompositor compositor;
+ compositor.setTitle(QLatin1String("QML Compositor"));
+ compositor.setGeometry(0, 0, 1024, 768);
+ compositor.show();
+
+ compositor.rootContext()->setContextProperty("compositor", &compositor);
+
+ QObject::connect(&compositor, SIGNAL(windowAdded(QVariant)), compositor.rootObject(), SLOT(windowAdded(QVariant)));
+ QObject::connect(&compositor, SIGNAL(windowResized(QVariant)), compositor.rootObject(), SLOT(windowResized(QVariant)));
+ QObject::connect(&compositor, SIGNAL(serverBufferItemCreated(QVariant)), compositor.rootObject(), SLOT(serverBufferItemCreated(QVariant)));
+
+ app.exec();
+ qDebug() << "ending" << glGetError();
+}
+
+#include "main.moc"
diff --git a/examples/wayland/server-buffer/compositor/qml/ServerBufferContainer.qml b/examples/wayland/server-buffer/compositor/qml/ServerBufferContainer.qml
new file mode 100644
index 000000000..7c7306e36
--- /dev/null
+++ b/examples/wayland/server-buffer/compositor/qml/ServerBufferContainer.qml
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Item {
+ id: container
+
+ Item {
+ id: bufferContainer
+ property var serverBuffer
+ property int depth: serverBuffer == null ? 0 : serverBuffer.depth
+ width: serverBuffer == null ? 0 : serverBuffer.width
+ height: serverBuffer == null ? 0 : serverBuffer.height
+ }
+
+ width: bufferContainer.width
+ height: bufferContainer.height + text.height
+
+ Rectangle {
+ anchors.top: bufferContainer.bottom
+ width: parent.width
+ height: text.paintedHeight
+ color: "light grey"
+ Text {
+ id: text
+ anchors.fill: parent
+ text: bufferContainer.depth == 8 ? "8 bit Server Side buffer" : "32 bit Server Side buffer\nHorizontal line should be blue"
+ z: bufferContainer.z + 1
+ wrapMode: Text.WordWrap
+ }
+ }
+
+ function setServerBuffer(serverBuffer) {
+ serverBuffer.parent = bufferContainer;
+ bufferContainer.serverBuffer = serverBuffer
+ }
+}
diff --git a/examples/wayland/server-buffer/compositor/qml/main.qml b/examples/wayland/server-buffer/compositor/qml/main.qml
new file mode 100644
index 000000000..c9d62be55
--- /dev/null
+++ b/examples/wayland/server-buffer/compositor/qml/main.qml
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtCompositor 1.0
+
+Item {
+ id: root
+
+ property var serverBufferContainerComponent : Qt.createComponent("qrc:/qml/ServerBufferContainer.qml")
+
+ Image {
+ id: background
+ anchors.fill: parent
+ fillMode: Image.Tile
+ source: "qrc:/images/background.jpg"
+ smooth: true
+ }
+
+ Row {
+ id: row
+ anchors.fill: parent
+ }
+
+ function windowAdded(window) {
+ var item = compositor.item(window);
+ item.parent = root;
+ item.surfaceDestroyed.connect(item.destroy);
+ }
+
+ function windowResized(window) {
+ }
+
+ function removeWindow(window) {
+ }
+
+ function serverBufferItemCreated(serverBufferItem) {
+ console.log("ServerBuffer item" + serverBufferItem);
+ if (serverBufferContainerComponent.status != Component.Ready) {
+ console.log("Error loading component:", component.errorString());
+ return;
+ }
+ var container = serverBufferContainerComponent.createObject(row);
+ container.setServerBuffer(serverBufferItem);
+ }
+}
diff --git a/examples/wayland/server-buffer/compositor/serverbufferitem.cpp b/examples/wayland/server-buffer/compositor/serverbufferitem.cpp
new file mode 100644
index 000000000..4a47c279d
--- /dev/null
+++ b/examples/wayland/server-buffer/compositor/serverbufferitem.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 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 "serverbufferitem.h"
+
+#include "serverbuffertextureprovider.h"
+
+#include <QtQuick/QSGSimpleTextureNode>
+#include <QtQuick/QQuickWindow>
+
+#include <QtCompositor/private/qwlserverbufferintegration_p.h>
+
+QT_BEGIN_NAMESPACE
+
+ServerBufferItem::ServerBufferItem(QtWayland::ServerBuffer *serverBuffer, QQuickItem *parent)
+ : QQuickItem(parent)
+ , m_server_buffer(serverBuffer)
+ , m_provider(new ServerBufferTextureProvider)
+ , m_useTextureAlpha(false)
+{
+ setFlag(QQuickItem::ItemHasContents);
+ setWidth(serverBuffer->size().width());
+ setHeight(serverBuffer->size().height());
+ update();
+}
+
+ServerBufferItem::~ServerBufferItem()
+{
+}
+
+bool ServerBufferItem::isYInverted() const
+{
+ return m_server_buffer->isYInverted();
+}
+
+int ServerBufferItem::depth() const
+{
+ return m_server_buffer->format() == QtWayland::ServerBuffer::RGBA32 ? 32 : 8;
+}
+
+QSGTextureProvider *ServerBufferItem::textureProvider() const
+{
+ return m_provider;
+}
+
+void ServerBufferItem::updateTexture()
+{
+ if (m_provider->texture())
+ return;
+
+ QQuickWindow::CreateTextureOptions opt = QQuickWindow::TextureHasAlphaChannel;
+ GLuint texture;
+ glGenTextures(1,&texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+ m_server_buffer->bindTextureToBuffer();
+ m_provider->setTexture(window()->createTextureFromId(texture, m_server_buffer->size(), opt));
+}
+
+QSGNode *ServerBufferItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
+{
+ updateTexture();
+ QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode *>(oldNode);
+
+ if (!node) {
+ node = new QSGSimpleTextureNode();
+ }
+
+ node->setTexture(m_provider->texture());
+
+ if (isYInverted()) {
+ node->setRect(0, height(), width(), -height());
+ } else {
+ node->setRect(0, 0, width(), height());
+ }
+
+ return node;
+}
+
+void ServerBufferItem::setUseTextureAlpha(bool useTextureAlpha)
+{
+ m_useTextureAlpha = useTextureAlpha;
+
+ if ((flags() & ItemHasContents) != 0) {
+ update();
+ }
+}
+
+QT_END_NAMESPACE
+
diff --git a/examples/wayland/server-buffer/compositor/serverbufferitem.h b/examples/wayland/server-buffer/compositor/serverbufferitem.h
new file mode 100644
index 000000000..31fad4e86
--- /dev/null
+++ b/examples/wayland/server-buffer/compositor/serverbufferitem.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 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 SERVERBUFFERITEM_H
+#define SERVERBUFFERITEM_H
+
+#include <QtQuick/QQuickItem>
+#include <QtQuick/qsgtexture.h>
+
+#include <QtQuick/qsgtextureprovider.h>
+
+QT_BEGIN_NAMESPACE
+
+class ServerBufferTextureProvider;
+
+namespace QtWayland {
+class ServerBuffer;
+}
+
+class ServerBufferItem : public QQuickItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QtWayland::ServerBuffer *serverBuffer READ serverBuffer CONSTANT)
+ Q_PROPERTY(bool useTextureAlpha READ useTextureAlpha WRITE setUseTextureAlpha NOTIFY useTextureAlphaChanged)
+ Q_PROPERTY(bool isYInverted READ isYInverted NOTIFY yInvertedChanged)
+ Q_PROPERTY(int depth READ depth CONSTANT)
+
+public:
+ ServerBufferItem(QtWayland::ServerBuffer *serverBuffer, QQuickItem *parent = 0);
+ ~ServerBufferItem();
+
+ QtWayland::ServerBuffer *serverBuffer() const { return m_server_buffer; }
+
+ bool isYInverted() const;
+ int depth() const;
+
+ bool isTextureProvider() const { return true; }
+ QSGTextureProvider *textureProvider() const;
+
+ bool useTextureAlpha() const { return m_useTextureAlpha; }
+ void setUseTextureAlpha(bool useTextureAlpha);
+
+ void setDamagedFlag(bool on);
+
+signals:
+ void useTextureAlphaChanged();
+ void yInvertedChanged();
+ void serverBufferChanged();
+
+protected:
+ QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *);
+
+private:
+ void updateTexture();
+ QtWayland::ServerBuffer *m_server_buffer;
+ ServerBufferTextureProvider *m_provider;
+ bool m_useTextureAlpha;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/examples/wayland/server-buffer/compositor/serverbuffertextureprovider.h b/examples/wayland/server-buffer/compositor/serverbuffertextureprovider.h
new file mode 100644
index 000000000..76ff5a4ac
--- /dev/null
+++ b/examples/wayland/server-buffer/compositor/serverbuffertextureprovider.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 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 SERVERBUFFERTEXTUREPROVIDER_H
+#define SERVERBUFFERTEXTUREPROVIDER_H
+
+#include <QtQuick/QSGTextureProvider>
+
+QT_BEGIN_NAMESPACE
+
+class ServerBufferTextureProvider : public QSGTextureProvider
+{
+public:
+ ServerBufferTextureProvider() : t(0) { }
+ ~ServerBufferTextureProvider() { delete t; }
+
+ QSGTexture *texture() const {
+ if (t) {
+ t->setHorizontalWrapMode(QSGTexture::ClampToEdge);
+ t->setVerticalWrapMode(QSGTexture::ClampToEdge);
+ t->setFiltering(QSGTexture::Linear);
+ }
+ return t;
+ }
+
+ void setTexture(QSGTexture *texture) {
+ if (texture != t) {
+ t = texture;
+ emit textureChanged();
+ }
+ }
+
+ bool smooth;
+private:
+ QSGTexture *t;
+};
+
+QT_END_NAMESPACE
+
+#endif //SERVERBUFFERTEXTUREPROVIDER_H