diff options
Diffstat (limited to 'examples/server-buffer/compositor')
-rw-r--r-- | examples/server-buffer/compositor/compositor.pro | 20 | ||||
-rw-r--r-- | examples/server-buffer/compositor/compositor.qrc | 7 | ||||
-rw-r--r-- | examples/server-buffer/compositor/images/background.jpg | bin | 0 -> 30730 bytes | |||
-rw-r--r-- | examples/server-buffer/compositor/main.cpp | 274 | ||||
-rw-r--r-- | examples/server-buffer/compositor/qml/ServerBufferContainer.qml | 75 | ||||
-rw-r--r-- | examples/server-buffer/compositor/qml/main.qml | 84 | ||||
-rw-r--r-- | examples/server-buffer/compositor/serverbufferitem.cpp | 122 | ||||
-rw-r--r-- | examples/server-buffer/compositor/serverbufferitem.h | 96 | ||||
-rw-r--r-- | examples/server-buffer/compositor/serverbuffertextureprovider.h | 77 |
9 files changed, 755 insertions, 0 deletions
diff --git a/examples/server-buffer/compositor/compositor.pro b/examples/server-buffer/compositor/compositor.pro new file mode 100644 index 000000000..8d7f48820 --- /dev/null +++ b/examples/server-buffer/compositor/compositor.pro @@ -0,0 +1,20 @@ +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 + +DEFINES += QT_COMPOSITOR_QUICK diff --git a/examples/server-buffer/compositor/compositor.qrc b/examples/server-buffer/compositor/compositor.qrc new file mode 100644 index 000000000..dbbbfb1cf --- /dev/null +++ b/examples/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/server-buffer/compositor/images/background.jpg b/examples/server-buffer/compositor/images/background.jpg Binary files differnew file mode 100644 index 000000000..445567fbd --- /dev/null +++ b/examples/server-buffer/compositor/images/background.jpg diff --git a/examples/server-buffer/compositor/main.cpp b/examples/server-buffer/compositor/main.cpp new file mode 100644 index 000000000..e6057cdd0 --- /dev/null +++ b/examples/server-buffer/compositor/main.cpp @@ -0,0 +1,274 @@ +/**************************************************************************** +** +** 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 "qwaylandcompositor.h" +#include "qwaylandsurface.h" +#include "qwaylandsurfaceitem.h" + +#include <QGuiApplication> +#include <QTimer> +#include <QPainter> +#include <QMouseEvent> + +#include <QQmlContext> + +#include <QQuickItem> +#include <QQuickView> + +#include "qwayland-server-share-buffer.h" +#include <QtCompositor/private/qwlcompositor_p.h> +#include <QtCompositor/qwaylandserverbufferintegration.h> + +#include "serverbufferitem.h" + +#include <QtGui/private/qdistancefield_p.h> + +class QmlCompositor + : public QQuickView + , public QWaylandCompositor + , public QtWaylandServer::qt_share_buffer +{ + Q_OBJECT + +public: + QmlCompositor() + : QWaylandCompositor(this, 0, DefaultExtensions | SubSurfaceExtension) + , QtWaylandServer::qt_share_buffer(QWaylandCompositor::handle()->wl_display()) + , 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(); + + connect(this, SIGNAL(frameSwapped()), this, SLOT(frameSwappedSlot())); + + connect(this, SIGNAL(sceneGraphInitialized()), this, SLOT(initiateServerBuffer()),Qt::DirectConnection); + connect(this, SIGNAL(serverBuffersCreated()), this, SLOT(createServerBufferItems())); + } + +signals: + void windowAdded(QVariant window); + void windowDestroyed(QVariant window); + void windowResized(QVariant window); + void serverBufferItemCreated(QVariant); + void serverBuffersCreated(); + +public slots: + void destroyWindow(QVariant window) + { + qvariant_cast<QObject *>(window)->deleteLater(); + } + + void destroyClientForWindow(QVariant window) + { + QWaylandSurface *surface = qobject_cast<QWaylandSurfaceItem *>(qvariant_cast<QObject *>(window))->surface(); + destroyClientForSurface(surface); + } + +private slots: + void surfaceMapped() { + QWaylandSurface *surface = qobject_cast<QWaylandSurface *>(sender()); + + QWaylandSurfaceItem *item = surface->surfaceItem(); + if (!item) { + item = new QWaylandSurfaceItem(surface, rootObject()); + item->setUseTextureAlpha(true); + } + + item->setTouchEventsEnabled(true); + emit windowAdded(QVariant::fromValue(static_cast<QQuickItem *>(item))); + } + + void surfaceUnmapped() { + QWaylandSurface *surface = qobject_cast<QWaylandSurface *>(sender()); + QQuickItem *item = surface->surfaceItem(); + emit windowDestroyed(QVariant::fromValue(item)); + } + + void surfaceDestroyed(QObject *object) { + QWaylandSurface *surface = static_cast<QWaylandSurface *>(object); + QQuickItem *item = surface->surfaceItem(); + emit windowDestroyed(QVariant::fromValue(item)); + } + + void frameSwappedSlot() { + frameFinished(); + } + + void initiateServerBuffer() + { + if (!QWaylandCompositor::handle()->serverBufferIntegration()) + return; + + openglContext()->makeCurrent(this); + + QWaylandServerBufferIntegration *sbi = QWaylandCompositor::handle()->serverBufferIntegration(); + if (!sbi) { + qWarning("Could not find a Server Buffer Integration"); + return; + } + if (sbi->supportsFormat(QWaylandServerBuffer::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(),QWaylandServerBuffer::RGBA32); + + GLuint texture_32_bit = m_server_buffer_32_bit->createTexture(); + glBindTexture(GL_TEXTURE_2D, texture_32_bit); + 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(QWaylandServerBuffer::A8)) { + QRawFont defaultRaw = QRawFont::fromFont(QFont(), QFontDatabase::Latin); + QVector<quint32> index = defaultRaw.glyphIndexesForString(QStringLiteral("A")); + QDistanceField distanceField(defaultRaw, index.front(), true); + QImage img = distanceField.toImage(QImage::Format_Indexed8); + + m_server_buffer_8_bit = sbi->createServerBuffer(img.size(), QWaylandServerBuffer::A8); + GLuint texture_8_bit = m_server_buffer_8_bit->createTexture(); + glBindTexture(GL_TEXTURE_2D, texture_8_bit); + + 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(destroyed(QObject *)), this, SLOT(surfaceDestroyed(QObject *))); + 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: + QWaylandServerBuffer *m_server_buffer_32_bit; + ServerBufferItem *m_server_buffer_item_32_bit; + QWaylandServerBuffer *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(windowDestroyed(QVariant)), compositor.rootObject(), SLOT(windowDestroyed(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/server-buffer/compositor/qml/ServerBufferContainer.qml b/examples/server-buffer/compositor/qml/ServerBufferContainer.qml new file mode 100644 index 000000000..7c7306e36 --- /dev/null +++ b/examples/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/server-buffer/compositor/qml/main.qml b/examples/server-buffer/compositor/qml/main.qml new file mode 100644 index 000000000..231fb5169 --- /dev/null +++ b/examples/server-buffer/compositor/qml/main.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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: 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) { + window.parent = root; + } + + function windowResized(window) { + } + + function windowDestroyed(window) { + compositor.destroyWindow(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/server-buffer/compositor/serverbufferitem.cpp b/examples/server-buffer/compositor/serverbufferitem.cpp new file mode 100644 index 000000000..ca3157ae0 --- /dev/null +++ b/examples/server-buffer/compositor/serverbufferitem.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** 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/qwaylandserverbufferintegration.h> + +QT_BEGIN_NAMESPACE + +ServerBufferItem::ServerBufferItem(QWaylandServerBuffer *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() == QWaylandServerBuffer::RGBA32 ? 32 : 8; +} + +QSGTextureProvider *ServerBufferItem::textureProvider() const +{ + return m_provider; +} + +void ServerBufferItem::updateTexture() +{ + if (m_provider->texture()) + return; + + QQuickWindow::CreateTextureOptions opt = QQuickWindow::TextureHasAlphaChannel; + m_provider->setTexture(window()->createTextureFromId(m_server_buffer->createTexture(), 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/server-buffer/compositor/serverbufferitem.h b/examples/server-buffer/compositor/serverbufferitem.h new file mode 100644 index 000000000..9391cb942 --- /dev/null +++ b/examples/server-buffer/compositor/serverbufferitem.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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; +class QWaylandServerBuffer; + +class ServerBufferItem : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QWaylandServerBuffer *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(QWaylandServerBuffer *serverBuffer, QQuickItem *parent = 0); + ~ServerBufferItem(); + + QWaylandServerBuffer *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(); + QWaylandServerBuffer *m_server_buffer; + ServerBufferTextureProvider *m_provider; + bool m_useTextureAlpha; +}; + +QT_END_NAMESPACE + +#endif diff --git a/examples/server-buffer/compositor/serverbuffertextureprovider.h b/examples/server-buffer/compositor/serverbuffertextureprovider.h new file mode 100644 index 000000000..76ff5a4ac --- /dev/null +++ b/examples/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 |