diff options
Diffstat (limited to 'examples/server-buffer')
-rw-r--r-- | examples/server-buffer/README | 17 | ||||
-rw-r--r-- | examples/server-buffer/client/client.pro | 15 | ||||
-rw-r--r-- | examples/server-buffer/client/main.cpp | 191 | ||||
-rw-r--r-- | examples/server-buffer/client/serverbufferrenderer.cpp | 133 | ||||
-rw-r--r-- | examples/server-buffer/client/serverbufferrenderer.h | 70 | ||||
-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 | 279 | ||||
-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 | 126 | ||||
-rw-r--r-- | examples/server-buffer/compositor/serverbufferitem.h | 96 | ||||
-rw-r--r-- | examples/server-buffer/compositor/serverbuffertextureprovider.h | 77 | ||||
-rw-r--r-- | examples/server-buffer/server-buffer.pro | 3 | ||||
-rw-r--r-- | examples/server-buffer/share-buffer.xml | 46 |
16 files changed, 1239 insertions, 0 deletions
diff --git a/examples/server-buffer/README b/examples/server-buffer/README new file mode 100644 index 00000000..762db423 --- /dev/null +++ b/examples/server-buffer/README @@ -0,0 +1,17 @@ +This is the example to demonstrate the server buffer interfaces + +Compile up both compositor and client. + +If you have the drm-egl-server buffer integration (and your running Mesa) +then start the compositor with: + +# QT_WAYLAND_SERVER_BUFFER_INTEGRATION=drm-egl-server ./compositor + +The compositor is using the hardware integration extension to boradcast +to all clients to use the same server buffer integration, so all you need +to do is to start the client with + +# ./client -platform wayland + +You should then see a red box in top left corner, with a black cross and +a horisontal line in the top half (centered). diff --git a/examples/server-buffer/client/client.pro b/examples/server-buffer/client/client.pro new file mode 100644 index 00000000..1296ed18 --- /dev/null +++ b/examples/server-buffer/client/client.pro @@ -0,0 +1,15 @@ +TEMPLATE = app +TARGET = client +INCLUDEPATH += . + +QT += waylandclient-private + +CONFIG += wayland-scanner +WAYLANDCLIENTSOURCES += ../share-buffer.xml + +SOURCES += \ + main.cpp \ + serverbufferrenderer.cpp + +HEADERS += \ + serverbufferrenderer.h diff --git a/examples/server-buffer/client/main.cpp b/examples/server-buffer/client/main.cpp new file mode 100644 index 00000000..b5ce8aec --- /dev/null +++ b/examples/server-buffer/client/main.cpp @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** 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 "serverbufferrenderer.h" + +#include <QtGui/QWindow> +#include <QtGui/QGuiApplication> +#include <QtGui/private/qguiapplication_p.h> +#include <QtGui/qpa/qplatformnativeinterface.h> +#include <QtGui/QOpenGLContext> +#include <QtGui/QOpenGLVertexArrayObject> +#include <QtGui/QOpenGLShaderProgram> +#include <QtGui/QOpenGLTexture> +#include <QtCore/QTimer> + +#include "qwayland-share-buffer.h" +#include <QtWaylandClient/private/qwayland-wayland.h> +#include <QtWaylandClient/private/qwaylandserverbufferintegration_p.h> +#include <QtWaylandClient/private/qwaylanddisplay_p.h> +#include <QtWaylandClient/private/qwaylandintegration_p.h> + + +class Window + : public QWindow + , public QtWayland::wl_registry + , public QtWayland::qt_share_buffer +{ + Q_OBJECT +public: + Window(QWindow *parent = 0) + : QWindow(parent) + , m_context(0) + { + setSurfaceType(QSurface::OpenGLSurface); + QSurfaceFormat sformat = format(); + sformat.setAlphaBufferSize(8); + sformat.setRedBufferSize(8); + sformat.setGreenBufferSize(8); + sformat.setBlueBufferSize(8); + setFormat(sformat); + create(); + + if (!QGuiApplication::platformNativeInterface() || !QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("wl_display")) { + qDebug() << "This application requires a wayland plugin"; + QCoreApplication::quit(); + return; + } + + QWaylandIntegration *wayland_integration = static_cast<QWaylandIntegration *>(QGuiApplicationPrivate::platformIntegration()); + + m_server_buffer_integration = wayland_integration->serverBufferIntegration(); + if (!m_server_buffer_integration) { + qDebug() << "This application requires a working serverBufferIntegration"; + QCoreApplication::quit(); + return; + } + + + QWaylandDisplay *wayland_display = wayland_integration->display(); + struct ::wl_registry *registry = wl_display_get_registry(wayland_display->wl_display()); + wl_proxy_set_queue(reinterpret_cast<struct wl_proxy *>(registry), wayland_display->wl_event_queue()); + QtWayland::wl_registry::init(registry); + } + +public slots: + void render() + { + if (m_server_buffer_list.isEmpty()) + return; + + if (!m_context) { + m_context = new QOpenGLContext(this); + m_context->setFormat(format()); + m_context->create(); + } + + m_context->makeCurrent(this); + + glBindFramebuffer(GL_FRAMEBUFFER, m_context->defaultFramebufferObject()); + + glViewport(0, 0, width() * devicePixelRatio(), height() * devicePixelRatio()); + glClearColor(0.f, 0.f, 0.0f, 1.f); + glClear(GL_COLOR_BUFFER_BIT); + + qreal x = 0; + for (int i = 0; i < m_server_buffer_list.size(); i++) { + ServerBufferRenderer *renderer = static_cast<ServerBufferRenderer *>(m_server_buffer_list[i]->userData()); + if (!renderer) { + renderer = new ServerBufferRenderer(m_server_buffer_list.at(i)); + } + + const QSizeF buffer_size = m_server_buffer_list.at(i)->size(); + qreal scale_x = buffer_size.width() / width(); + qreal scale_y = buffer_size.height() / height(); + qreal translate_left = (((buffer_size.width() / 2) / width()) * 2) - 1; + qreal translate_top = -(((buffer_size.height() / 2) / height()) * 2) + 1; + qreal translate_x = translate_left + ((x / width())*2); + + QMatrix4x4 transform; + transform.translate(translate_x, translate_top); + transform.scale(scale_x, scale_y); + renderer->render(transform); + + x += buffer_size.width(); + } + + m_context->swapBuffers(this); + } + +protected: + void registry_global(uint32_t name, const QString &interface, uint32_t version) Q_DECL_OVERRIDE + { + Q_UNUSED(version); + if (interface == QStringLiteral("qt_share_buffer")) { + QtWayland::qt_share_buffer::init(QtWayland::wl_registry::object(), name); + } + } + + void share_buffer_cross_buffer(struct ::qt_server_buffer *buffer) Q_DECL_OVERRIDE + { + QWaylandServerBuffer *serverBuffer = m_server_buffer_integration->serverBuffer(buffer); + if (m_server_buffer_list.isEmpty()) { + setWidth(serverBuffer->size().width()); + setHeight(serverBuffer->size().height()); + } else { + setWidth(width() + serverBuffer->size().width()); + setHeight(std::max(serverBuffer->size().height(), height())); + } + m_server_buffer_list.append(serverBuffer); + render(); + } + +private: + QWaylandServerBufferIntegration *m_server_buffer_integration; + QList<QWaylandServerBuffer *>m_server_buffer_list; + GLuint m_server_buffer_texture; + QOpenGLContext *m_context; + QOpenGLVertexArrayObject *m_vao; + GLuint m_vertexbuffer; + GLuint m_texture_coords; + QOpenGLShaderProgram *m_shader_program; + QOpenGLTexture *m_image_texture; +}; + +int main (int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + Window window; + window.show(); + return app.exec(); +} + +#include "main.moc" diff --git a/examples/server-buffer/client/serverbufferrenderer.cpp b/examples/server-buffer/client/serverbufferrenderer.cpp new file mode 100644 index 00000000..b9aa7a01 --- /dev/null +++ b/examples/server-buffer/client/serverbufferrenderer.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** 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 "serverbufferrenderer.h" + +#include <QtGui/QOpenGLVertexArrayObject> +#include <QtGui/QOpenGLShaderProgram> +static const GLfloat uv_coords[] = { + 1,1, + 1,0, + 0,1, + 0,0, +}; + +static const GLfloat vertex_coords[] = { + -1,-1,0, + -1,1,0, + 1,-1,0, + 1,1,0, +}; + +static const char vertex_shader[] = + "attribute vec3 vertexCoord;" + "attribute vec2 textureCoord;" + "uniform mat4 transform;" + "varying mediump vec2 uv;" + "void main() {" + " uv = textureCoord;" + " gl_Position = transform * vec4(vertexCoord,1);" + "}"; + +static const char fragment_shader[] = + "varying mediump vec2 uv;" + "uniform sampler2D textureSampler;" + "void main() {" + " gl_FragColor = texture2D(textureSampler, uv);" + "}"; + +ServerBufferRenderer::ServerBufferRenderer(QWaylandServerBuffer *serverBuffer) + : m_server_buffer(serverBuffer) + , m_texture(0) + , m_vao(new QOpenGLVertexArrayObject()) + , m_program(new QOpenGLShaderProgram()) + , m_vertexbuffer(0) + , m_texture_coords(0) + +{ + Q_ASSERT(serverBuffer); + if (serverBuffer->userData()) { + qWarning("ServerBufferRenderer: Will over QWaylandServerBuffers %p userdata %p", serverBuffer, serverBuffer->userData()); + } + serverBuffer->setUserData(this); + m_vao->create(); + m_vao->bind(); + + m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertex_shader); + m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragment_shader); + if (!m_program->link()) { + qDebug() << m_program->log(); + } + + glGenTextures(1,&m_texture); + glBindTexture(GL_TEXTURE_2D, m_texture); + serverBuffer->bindTextureToBuffer(); + + glGenBuffers(1, &m_vertexbuffer); + glBindBuffer(GL_ARRAY_BUFFER, m_vertexbuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_coords), vertex_coords, GL_STATIC_DRAW); + m_program->setAttributeBuffer("vertexCoord", GL_FLOAT, 0, 3, 0); + + glGenBuffers(1, &m_texture_coords); + glBindBuffer(GL_ARRAY_BUFFER, m_texture_coords); + glBufferData(GL_ARRAY_BUFFER, sizeof(uv_coords), uv_coords, GL_STATIC_DRAW); + m_program->setAttributeBuffer("textureCoord", GL_FLOAT, 0, 2, 0); + + m_program->enableAttributeArray("vertexCoord"); + m_program->enableAttributeArray("textureCoord"); + + m_vao->release(); + glBindBuffer(GL_ARRAY_BUFFER, 0); +} + +void ServerBufferRenderer::render(const QMatrix4x4 &transform) +{ + m_vao->bind(); + + m_program->bind(); + m_program->setUniformValue("transform", transform); + + glBindTexture(GL_TEXTURE_2D, m_texture); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + m_vao->release(); + glBindBuffer(GL_ARRAY_BUFFER, 0); +} diff --git a/examples/server-buffer/client/serverbufferrenderer.h b/examples/server-buffer/client/serverbufferrenderer.h new file mode 100644 index 00000000..58f0c704 --- /dev/null +++ b/examples/server-buffer/client/serverbufferrenderer.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef SERVERBUFFERRENDERER_H +#define SERVERBUFFERRENDERER_H + +#include <QtWaylandClient/private/qwaylandserverbufferintegration_p.h> + +#include <QMatrix4x4> +QT_BEGIN_NAMESPACE + +class QOpenGLVertexArrayObject; +class QOpenGLShaderProgram; + +class ServerBufferRenderer +{ +public: + ServerBufferRenderer(QWaylandServerBuffer *serverBuffer); + + void render(const QMatrix4x4 &transform); +private: + QWaylandServerBuffer *m_server_buffer; + GLuint m_texture; + + QOpenGLVertexArrayObject *m_vao; + QOpenGLShaderProgram *m_program; + + GLuint m_vertexbuffer; + GLuint m_texture_coords; +}; + +QT_END_NAMESPACE +#endif diff --git a/examples/server-buffer/compositor/compositor.pro b/examples/server-buffer/compositor/compositor.pro new file mode 100644 index 00000000..8d7f4882 --- /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 00000000..dbbbfb1c --- /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 00000000..445567fb --- /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 00000000..c266b224 --- /dev/null +++ b/examples/server-buffer/compositor/main.cpp @@ -0,0 +1,279 @@ +/**************************************************************************** +** +** 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 <QOpenGLContext> + +#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; + 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(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; + 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(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 00000000..7c7306e3 --- /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 00000000..231fb516 --- /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 00000000..8227b871 --- /dev/null +++ b/examples/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/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; + 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/server-buffer/compositor/serverbufferitem.h b/examples/server-buffer/compositor/serverbufferitem.h new file mode 100644 index 00000000..9391cb94 --- /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 00000000..76ff5a4a --- /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 diff --git a/examples/server-buffer/server-buffer.pro b/examples/server-buffer/server-buffer.pro new file mode 100644 index 00000000..16c55625 --- /dev/null +++ b/examples/server-buffer/server-buffer.pro @@ -0,0 +1,3 @@ +TEMPLATE=subdirs + +SUBDIRS += client compositor diff --git a/examples/server-buffer/share-buffer.xml b/examples/server-buffer/share-buffer.xml new file mode 100644 index 00000000..57a1fd2c --- /dev/null +++ b/examples/server-buffer/share-buffer.xml @@ -0,0 +1,46 @@ +<protocol name="share_buffer"> + + <copyright> + Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). + Contact: http://www.qt-project.org/legal + + This file is part of the plugins 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$ + </copyright> + + <interface name="qt_share_buffer" version="1"> + <event name="cross_buffer"> + <arg name="buffer" type="object" interface="qt_server_buffer"/> + </event> + </interface> +</protocol> |