summaryrefslogtreecommitdiffstats
path: root/src/compositor/wayland_wrapper/wlshmbuffer.cpp
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@nokia.com>2011-12-05 17:09:02 +0100
committerLaszlo Agocs <laszlo.p.agocs@nokia.com>2011-12-07 09:58:35 +0100
commit4c89518228012ddc3602eab405e4b5fb8108fcdf (patch)
tree615d4fdc38999e408d52998c39760064d223b652 /src/compositor/wayland_wrapper/wlshmbuffer.cpp
parent542eca71e074b5110df2aaf822449bf7d6ec2b91 (diff)
Make wayland actually a module
Also fix so that QtCompositor can be built as shared object. + fix so that the default QT_WAYLAND_GL_CONFIG is wayland_egl Change-Id: I02b72e99286584426bd37ab2d00bbc84af11efdc Reviewed-by: Laszlo Agocs <laszlo.p.agocs@nokia.com>
Diffstat (limited to 'src/compositor/wayland_wrapper/wlshmbuffer.cpp')
-rw-r--r--src/compositor/wayland_wrapper/wlshmbuffer.cpp141
1 files changed, 141 insertions, 0 deletions
diff --git a/src/compositor/wayland_wrapper/wlshmbuffer.cpp b/src/compositor/wayland_wrapper/wlshmbuffer.cpp
new file mode 100644
index 000000000..c5126aeaa
--- /dev/null
+++ b/src/compositor/wayland_wrapper/wlshmbuffer.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** This file is part of QtCompositor**
+**
+** Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation qt-info@nokia.com
+**
+** You may use this file under the terms of the BSD license as follows:
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**
+** Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+**
+** Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in the
+** documentation and/or other materials provided with the distribution.
+**
+** Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the
+** names of its contributors may be used to endorse or promote products
+** derived from this software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+**
+****************************************************************************/
+
+#include "wlshmbuffer.h"
+
+#include "wldisplay.h"
+#include "wlcompositor.h"
+
+#include <QtCore/QDebug>
+
+#include <sys/mman.h>
+
+namespace Wayland {
+
+ShmBuffer::ShmBuffer(struct wl_buffer *buffer)
+ : m_buffer(buffer)
+{
+ m_buffer->user_data = this;
+ m_data = wl_shm_buffer_get_data(m_buffer);
+ m_stride = wl_shm_buffer_get_stride(m_buffer);
+
+ damage();
+}
+
+ShmBuffer::~ShmBuffer()
+{
+}
+
+QImage ShmBuffer::image() const
+{
+ return m_image;
+}
+
+QSize ShmBuffer::size() const
+{
+ return QSize(m_buffer->width, m_buffer->height);
+}
+
+void ShmBuffer::damage()
+{
+ QImage::Format imageFormat = QImage::Format_Invalid;
+
+ imageFormat = QImage::Format_ARGB32_Premultiplied;
+
+ m_image = QImage(static_cast<uchar *>(m_data),m_buffer->width, m_buffer->height,m_stride,imageFormat);
+
+}
+
+static ShmHandler *handlerInstance;
+
+ShmHandler::ShmHandler(Display *display)
+ : m_display(display)
+{
+ handlerInstance = this;
+ m_shm = wl_shm_init(m_display->handle(),&shm_callbacks);
+}
+
+ShmHandler::~ShmHandler()
+{
+ wl_shm_finish(m_shm);
+}
+
+struct wl_shm_callbacks ShmHandler::shm_callbacks = {
+ buffer_created_callback,
+ buffer_damaged_callback,
+ buffer_destroyed_callback
+};
+
+void ShmHandler::buffer_created_callback(struct wl_buffer *buffer)
+{
+ ShmBuffer *newBuffer = new ShmBuffer(buffer);
+ Q_UNUSED(newBuffer);
+}
+
+void ShmHandler::buffer_damaged_callback(struct wl_buffer *buffer,
+ int32_t x, int32_t y,
+ int32_t width, int32_t height)
+{
+ Q_UNUSED(buffer);
+ Q_UNUSED(x);
+ Q_UNUSED(y);
+ Q_UNUSED(width);
+ Q_UNUSED(height);
+ //damage has the responsibillity to update the QImage
+ //for now we just recrate the entire QImage as we need a new
+ //hash key for texture uploads
+ static_cast<ShmBuffer *>(buffer->user_data)->damage();
+}
+
+void ShmHandler::buffer_destroyed_callback(struct wl_buffer *buffer)
+{
+ ShmBuffer *shmbuf = static_cast<ShmBuffer *>(buffer->user_data);
+ for (int i = 0; i < handlerInstance->m_extraCallbacks.count(); ++i)
+ handlerInstance->m_extraCallbacks.at(i)(shmbuf);
+ delete shmbuf;
+}
+
+void ShmHandler::addDestroyCallback(DestroyCallback callback)
+{
+ if (!m_extraCallbacks.contains(callback))
+ m_extraCallbacks.append(callback);
+}
+
+}