From 6ce6b8a378b0d97ba950240ffb048a4b7e485235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 20 Jun 2011 13:29:26 +0200 Subject: Rename QWindowSurface -> QBackingStore and split into platform / public. Also get rid of GL window surface and related classes. --- src/plugins/platforms/minimal/minimal.pro | 4 +- .../platforms/minimal/qminimalbackingstore.cpp | 85 ++++++ .../platforms/minimal/qminimalbackingstore.h | 67 +++++ .../platforms/minimal/qminimalintegration.cpp | 7 +- .../platforms/minimal/qminimalintegration.h | 2 +- .../platforms/minimal/qminimalwindowsurface.cpp | 86 ------- .../platforms/minimal/qminimalwindowsurface.h | 68 ----- src/plugins/platforms/wayland/qwaylandcursor.cpp | 2 +- .../platforms/wayland/qwaylandintegration.cpp | 7 +- .../platforms/wayland/qwaylandintegration.h | 2 +- .../platforms/wayland/qwaylandshmbackingstore.cpp | 143 +++++++++++ .../platforms/wayland/qwaylandshmbackingstore.h | 83 ++++++ .../platforms/wayland/qwaylandshmsurface.cpp | 144 ----------- src/plugins/platforms/wayland/qwaylandshmsurface.h | 83 ------ src/plugins/platforms/wayland/wayland.pro | 4 +- src/plugins/platforms/xcb/qxcbbackingstore.cpp | 284 +++++++++++++++++++++ src/plugins/platforms/xcb/qxcbbackingstore.h | 72 ++++++ src/plugins/platforms/xcb/qxcbintegration.cpp | 7 +- src/plugins/platforms/xcb/qxcbintegration.h | 2 +- src/plugins/platforms/xcb/qxcbwindow.cpp | 10 +- src/plugins/platforms/xcb/qxcbwindowsurface.cpp | 282 -------------------- src/plugins/platforms/xcb/qxcbwindowsurface.h | 72 ------ src/plugins/platforms/xcb/xcb.pro | 4 +- 23 files changed, 756 insertions(+), 764 deletions(-) create mode 100644 src/plugins/platforms/minimal/qminimalbackingstore.cpp create mode 100644 src/plugins/platforms/minimal/qminimalbackingstore.h delete mode 100644 src/plugins/platforms/minimal/qminimalwindowsurface.cpp delete mode 100644 src/plugins/platforms/minimal/qminimalwindowsurface.h create mode 100644 src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp create mode 100644 src/plugins/platforms/wayland/qwaylandshmbackingstore.h delete mode 100644 src/plugins/platforms/wayland/qwaylandshmsurface.cpp delete mode 100644 src/plugins/platforms/wayland/qwaylandshmsurface.h create mode 100644 src/plugins/platforms/xcb/qxcbbackingstore.cpp create mode 100644 src/plugins/platforms/xcb/qxcbbackingstore.h delete mode 100644 src/plugins/platforms/xcb/qxcbwindowsurface.cpp delete mode 100644 src/plugins/platforms/xcb/qxcbwindowsurface.h (limited to 'src/plugins') diff --git a/src/plugins/platforms/minimal/minimal.pro b/src/plugins/platforms/minimal/minimal.pro index d51b6b2ed0..53ae1b1319 100644 --- a/src/plugins/platforms/minimal/minimal.pro +++ b/src/plugins/platforms/minimal/minimal.pro @@ -6,9 +6,9 @@ DESTDIR = $$QT.gui.plugins/platforms SOURCES = main.cpp \ qminimalintegration.cpp \ - qminimalwindowsurface.cpp + qminimalbackingstore.cpp HEADERS = qminimalintegration.h \ - qminimalwindowsurface.h + qminimalbackingstore.h target.path += $$[QT_INSTALL_PLUGINS]/platforms INSTALLS += target diff --git a/src/plugins/platforms/minimal/qminimalbackingstore.cpp b/src/plugins/platforms/minimal/qminimalbackingstore.cpp new file mode 100644 index 0000000000..bd4f04dfcd --- /dev/null +++ b/src/plugins/platforms/minimal/qminimalbackingstore.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include "qminimalbackingstore.h" +#include +#include + +QT_BEGIN_NAMESPACE + +QMinimalBackingStore::QMinimalBackingStore(QWindow *window) + : QPlatformBackingStore(window) +{ + //qDebug() << "QMinimalBackingStore::QMinimalBackingStore:" << (long)this; +} + +QMinimalBackingStore::~QMinimalBackingStore() +{ +} + +QPaintDevice *QMinimalBackingStore::paintDevice() +{ + //qDebug() << "QMinimalBackingStore::paintDevice"; + return &mImage; +} + +void QMinimalBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(window); + Q_UNUSED(region); + Q_UNUSED(offset); + + static int c = 0; + QString filename = QString("output%1.png").arg(c++, 4, 10, QLatin1Char('0')); + qDebug() << "QMinimalBackingStore::flush() saving contents to" << filename.toLocal8Bit().constData(); + mImage.save(filename); +} + +void QMinimalBackingStore::resize(const QSize &size, const QRegion &) +{ + //qDebug() << "QMinimalBackingStore::setGeometry:" << (long)this << rect; + QImage::Format format = QGuiApplicationPrivate::platformIntegration()->screens().first()->format(); + if (mImage.size() != size) + mImage = QImage(size, format); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/minimal/qminimalbackingstore.h b/src/plugins/platforms/minimal/qminimalbackingstore.h new file mode 100644 index 0000000000..9b61275e9d --- /dev/null +++ b/src/plugins/platforms/minimal/qminimalbackingstore.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBACKINGSTORE_MINIMAL_H +#define QBACKINGSTORE_MINIMAL_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QMinimalBackingStore : public QPlatformBackingStore +{ +public: + QMinimalBackingStore(QWindow *window); + ~QMinimalBackingStore(); + + QPaintDevice *paintDevice(); + void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); + void resize(const QSize &size, const QRegion &staticContents); + +private: + QImage mImage; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/minimal/qminimalintegration.cpp b/src/plugins/platforms/minimal/qminimalintegration.cpp index 23bade99b6..c3300ce3b8 100644 --- a/src/plugins/platforms/minimal/qminimalintegration.cpp +++ b/src/plugins/platforms/minimal/qminimalintegration.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qminimalintegration.h" -#include "qminimalwindowsurface.h" +#include "qminimalbackingstore.h" #include #include @@ -75,8 +75,7 @@ QPlatformWindow *QMinimalIntegration::createPlatformWindow(QWindow *window) cons return new QPlatformWindow(window); } -QWindowSurface *QMinimalIntegration::createWindowSurface(QWindow *window, WId winId) const +QPlatformBackingStore *QMinimalIntegration::createPlatformBackingStore(QWindow *window) const { - Q_UNUSED(winId); - return new QMinimalWindowSurface(window); + return new QMinimalBackingStore(window); } diff --git a/src/plugins/platforms/minimal/qminimalintegration.h b/src/plugins/platforms/minimal/qminimalintegration.h index 6ac45c2385..efb0f352d4 100644 --- a/src/plugins/platforms/minimal/qminimalintegration.h +++ b/src/plugins/platforms/minimal/qminimalintegration.h @@ -73,7 +73,7 @@ public: QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWindow *window) const; - QWindowSurface *createWindowSurface(QWindow *window, WId winId) const; + QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QList screens() const { return mScreens; } diff --git a/src/plugins/platforms/minimal/qminimalwindowsurface.cpp b/src/plugins/platforms/minimal/qminimalwindowsurface.cpp deleted file mode 100644 index f28b34a000..0000000000 --- a/src/plugins/platforms/minimal/qminimalwindowsurface.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qminimalwindowsurface.h" -#include -#include - -QT_BEGIN_NAMESPACE - -QMinimalWindowSurface::QMinimalWindowSurface(QWindow *window) - : QWindowSurface(window) -{ - //qDebug() << "QMinimalWindowSurface::QMinimalWindowSurface:" << (long)this; -} - -QMinimalWindowSurface::~QMinimalWindowSurface() -{ -} - -QPaintDevice *QMinimalWindowSurface::paintDevice() -{ - //qDebug() << "QMinimalWindowSurface::paintDevice"; - return &mImage; -} - -void QMinimalWindowSurface::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) -{ - Q_UNUSED(window); - Q_UNUSED(region); - Q_UNUSED(offset); - - static int c = 0; - QString filename = QString("output%1.png").arg(c++, 4, 10, QLatin1Char('0')); - qDebug() << "QMinimalWindowSurface::flush() saving contents to" << filename.toLocal8Bit().constData(); - mImage.save(filename); -} - -void QMinimalWindowSurface::resize(const QSize &size) -{ - //qDebug() << "QMinimalWindowSurface::setGeometry:" << (long)this << rect; - QWindowSurface::resize(size); - QImage::Format format = QGuiApplicationPrivate::platformIntegration()->screens().first()->format(); - if (mImage.size() != size) - mImage = QImage(size, format); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/minimal/qminimalwindowsurface.h b/src/plugins/platforms/minimal/qminimalwindowsurface.h deleted file mode 100644 index 943cdc43e1..0000000000 --- a/src/plugins/platforms/minimal/qminimalwindowsurface.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSURFACE_MINIMAL_H -#define QWINDOWSURFACE_MINIMAL_H - -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -class QMinimalWindowSurface : public QWindowSurface -{ -public: - QMinimalWindowSurface(QWindow *window); - ~QMinimalWindowSurface(); - - QPaintDevice *paintDevice(); - void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); - void resize(const QSize &size); - -private: - QImage mImage; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/platforms/wayland/qwaylandcursor.cpp b/src/plugins/platforms/wayland/qwaylandcursor.cpp index d69d618591..6612d67cb4 100644 --- a/src/plugins/platforms/wayland/qwaylandcursor.cpp +++ b/src/plugins/platforms/wayland/qwaylandcursor.cpp @@ -43,8 +43,8 @@ #include "qwaylanddisplay.h" #include "qwaylandinputdevice.h" -#include "qwaylandshmsurface.h" #include "qwaylandscreen.h" +#include "qwaylandshmbackingstore.h" #include diff --git a/src/plugins/platforms/wayland/qwaylandintegration.cpp b/src/plugins/platforms/wayland/qwaylandintegration.cpp index 090edfe324..9cd79e2978 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.cpp +++ b/src/plugins/platforms/wayland/qwaylandintegration.cpp @@ -42,7 +42,7 @@ #include "qwaylandintegration.h" #include "qwaylanddisplay.h" -#include "qwaylandshmsurface.h" +#include "qwaylandshmbackingstore.h" #include "qwaylandshmwindow.h" #include "qwaylandnativeinterface.h" #include "qwaylandclipboard.h" @@ -116,10 +116,9 @@ QPlatformGLContext *QWaylandIntegration::createPlatformGLContext(const QGuiGLFor #endif } -QWindowSurface *QWaylandIntegration::createWindowSurface(QWindow *window, WId winId) const +QPlatformBackingStore *QWaylandIntegration::createPlatformBackingStore(QWindow *window) const { - Q_UNUSED(winId); - return new QWaylandShmWindowSurface(window); + return new QWaylandShmBackingStore(window); } QPlatformFontDatabase *QWaylandIntegration::fontDatabase() const diff --git a/src/plugins/platforms/wayland/qwaylandintegration.h b/src/plugins/platforms/wayland/qwaylandintegration.h index e55dec3229..1e22191ff7 100644 --- a/src/plugins/platforms/wayland/qwaylandintegration.h +++ b/src/plugins/platforms/wayland/qwaylandintegration.h @@ -58,7 +58,7 @@ public: QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const; - QWindowSurface *createWindowSurface(QWindow *window, WId winId) const; + QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QList screens() const; diff --git a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp new file mode 100644 index 0000000000..ccb50a73fb --- /dev/null +++ b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qwaylandshmbackingstore.h" + +#include + +#include "qwaylanddisplay.h" +#include "qwaylandshmwindow.h" +#include "qwaylandscreen.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display, + const QSize &size, QImage::Format format) +{ + int stride = size.width() * 4; + int alloc = stride * size.height(); + char filename[] = "/tmp/wayland-shm-XXXXXX"; + int fd = mkstemp(filename); + if (fd < 0) + qWarning("open %s failed: %s", filename, strerror(errno)); + if (ftruncate(fd, alloc) < 0) { + qWarning("ftruncate failed: %s", strerror(errno)); + close(fd); + return; + } + uchar *data = (uchar *) + mmap(NULL, alloc, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + unlink(filename); + + if (data == (uchar *) MAP_FAILED) { + qWarning("mmap /dev/zero failed: %s", strerror(errno)); + close(fd); + return; + } + + mImage = QImage(data, size.width(), size.height(), stride, format); + mBuffer = display->createShmBuffer(fd, size.width(), size.height(), + stride, display->argbVisual()); + close(fd); +} + +QWaylandShmBuffer::~QWaylandShmBuffer(void) +{ + munmap((void *) mImage.constBits(), mImage.byteCount()); + wl_buffer_destroy(mBuffer); +} + +QWaylandShmBackingStore::QWaylandShmBackingStore(QWindow *window) + : QPlatformBackingStore(window) + , mBuffer(0) + , mDisplay(QWaylandScreen::waylandScreenFromWindow(window)->display()) +{ +} + +QWaylandShmBackingStore::~QWaylandShmBackingStore() +{ +} + +QPaintDevice *QWaylandShmBackingStore::paintDevice() +{ + return mBuffer->image(); +} + +void QWaylandShmBackingStore::beginPaint(const QRegion &) +{ + QWaylandShmWindow *waylandWindow = static_cast(window()->handle()); + Q_ASSERT(waylandWindow->windowType() == QWaylandWindow::Shm); + waylandWindow->waitForFrameSync(); +} + +void QWaylandShmBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(window); + Q_UNUSED(offset); + QWaylandShmWindow *waylandWindow = static_cast(window->handle()); + Q_ASSERT(waylandWindow->windowType() == QWaylandWindow::Shm); + waylandWindow->damage(region); +} + +void QWaylandShmBackingStore::resize(const QSize &size, const QRegion &) +{ + QWaylandShmWindow *waylandWindow = static_cast(window()->handle()); + Q_ASSERT(waylandWindow->windowType() == QWaylandWindow::Shm); + + QImage::Format format = QPlatformScreen::platformScreenForWindow(window())->format(); + + if (mBuffer != NULL && mBuffer->size() == size) + return; + + if (mBuffer != NULL) + delete mBuffer; + + mBuffer = new QWaylandShmBuffer(mDisplay, size, format); + + waylandWindow->attach(mBuffer); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/wayland/qwaylandshmbackingstore.h b/src/plugins/platforms/wayland/qwaylandshmbackingstore.h new file mode 100644 index 0000000000..5e6959dc2f --- /dev/null +++ b/src/plugins/platforms/wayland/qwaylandshmbackingstore.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDSHMBACKINGSTORE_H +#define QWAYLANDSHMBACKINGSTORE_H + +#include "qwaylandbuffer.h" +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QWaylandDisplay; + +class QWaylandShmBuffer : public QWaylandBuffer { +public: + QWaylandShmBuffer(QWaylandDisplay *display, + const QSize &size, QImage::Format format); + ~QWaylandShmBuffer(); + QSize size() const { return mImage.size(); } + QImage *image() { return &mImage; } +private: + QImage mImage; +}; + +class QWaylandShmBackingStore : public QPlatformBackingStore +{ +public: + QWaylandShmBackingStore(QWindow *window); + ~QWaylandShmBackingStore(); + + QPaintDevice *paintDevice(); + void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); + void resize(const QSize &size, const QRegion &staticContents); + void beginPaint(const QRegion &); + +private: + QWaylandShmBuffer *mBuffer; + QWaylandDisplay *mDisplay; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/wayland/qwaylandshmsurface.cpp b/src/plugins/platforms/wayland/qwaylandshmsurface.cpp deleted file mode 100644 index 520633811c..0000000000 --- a/src/plugins/platforms/wayland/qwaylandshmsurface.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qwaylandshmsurface.h" - -#include - -#include "qwaylanddisplay.h" -#include "qwaylandshmwindow.h" -#include "qwaylandscreen.h" - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display, - const QSize &size, QImage::Format format) -{ - int stride = size.width() * 4; - int alloc = stride * size.height(); - char filename[] = "/tmp/wayland-shm-XXXXXX"; - int fd = mkstemp(filename); - if (fd < 0) - qWarning("open %s failed: %s", filename, strerror(errno)); - if (ftruncate(fd, alloc) < 0) { - qWarning("ftruncate failed: %s", strerror(errno)); - close(fd); - return; - } - uchar *data = (uchar *) - mmap(NULL, alloc, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - unlink(filename); - - if (data == (uchar *) MAP_FAILED) { - qWarning("mmap /dev/zero failed: %s", strerror(errno)); - close(fd); - return; - } - - mImage = QImage(data, size.width(), size.height(), stride, format); - mBuffer = display->createShmBuffer(fd, size.width(), size.height(), - stride, display->argbVisual()); - close(fd); -} - -QWaylandShmBuffer::~QWaylandShmBuffer(void) -{ - munmap((void *) mImage.constBits(), mImage.byteCount()); - wl_buffer_destroy(mBuffer); -} - -QWaylandShmWindowSurface::QWaylandShmWindowSurface(QWindow *window) - : QWindowSurface(window) - , mBuffer(0) - , mDisplay(QWaylandScreen::waylandScreenFromWindow(window)->display()) -{ -} - -QWaylandShmWindowSurface::~QWaylandShmWindowSurface() -{ -} - -QPaintDevice *QWaylandShmWindowSurface::paintDevice() -{ - return mBuffer->image(); -} - -void QWaylandShmWindowSurface::beginPaint(const QRegion &) -{ - QWaylandShmWindow *waylandWindow = static_cast(window()->handle()); - Q_ASSERT(waylandWindow->windowType() == QWaylandWindow::Shm); - waylandWindow->waitForFrameSync(); -} - -void QWaylandShmWindowSurface::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) -{ - Q_UNUSED(window); - Q_UNUSED(offset); - QWaylandShmWindow *waylandWindow = static_cast(window->handle()); - Q_ASSERT(waylandWindow->windowType() == QWaylandWindow::Shm); - waylandWindow->damage(region); -} - -void QWaylandShmWindowSurface::resize(const QSize &size) -{ - QWaylandShmWindow *waylandWindow = static_cast(window()->handle()); - Q_ASSERT(waylandWindow->windowType() == QWaylandWindow::Shm); - - QWindowSurface::resize(size); - QImage::Format format = QPlatformScreen::platformScreenForWindow(window())->format(); - - if (mBuffer != NULL && mBuffer->size() == size) - return; - - if (mBuffer != NULL) - delete mBuffer; - - mBuffer = new QWaylandShmBuffer(mDisplay, size, format); - - waylandWindow->attach(mBuffer); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/wayland/qwaylandshmsurface.h b/src/plugins/platforms/wayland/qwaylandshmsurface.h deleted file mode 100644 index 1045709d7c..0000000000 --- a/src/plugins/platforms/wayland/qwaylandshmsurface.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSURFACE_WAYLAND_H -#define QWINDOWSURFACE_WAYLAND_H - -#include "qwaylandbuffer.h" -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QWaylandDisplay; - -class QWaylandShmBuffer : public QWaylandBuffer { -public: - QWaylandShmBuffer(QWaylandDisplay *display, - const QSize &size, QImage::Format format); - ~QWaylandShmBuffer(); - QSize size() const { return mImage.size(); } - QImage *image() { return &mImage; } -private: - QImage mImage; -}; - -class QWaylandShmWindowSurface : public QWindowSurface -{ -public: - QWaylandShmWindowSurface(QWindow *window); - ~QWaylandShmWindowSurface(); - - QPaintDevice *paintDevice(); - void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); - void resize(const QSize &size); - void beginPaint(const QRegion &); - -private: - QWaylandShmBuffer *mBuffer; - QWaylandDisplay *mDisplay; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/platforms/wayland/wayland.pro b/src/plugins/platforms/wayland/wayland.pro index 0a2084df3b..9010439939 100644 --- a/src/plugins/platforms/wayland/wayland.pro +++ b/src/plugins/platforms/wayland/wayland.pro @@ -13,7 +13,7 @@ QT += core-private gui-private opengl-private platformsupport-private SOURCES = main.cpp \ qwaylandintegration.cpp \ qwaylandnativeinterface.cpp \ - qwaylandshmsurface.cpp \ + qwaylandshmbackingstore.cpp \ qwaylandinputdevice.cpp \ qwaylandcursor.cpp \ qwaylanddisplay.cpp \ @@ -28,7 +28,7 @@ HEADERS = qwaylandintegration.h \ qwaylanddisplay.h \ qwaylandwindow.h \ qwaylandscreen.h \ - qwaylandshmsurface.h \ + qwaylandshmbackingstore.h \ qwaylandbuffer.h \ qwaylandshmwindow.h \ qwaylandclipboard.h diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.cpp b/src/plugins/platforms/xcb/qxcbbackingstore.cpp new file mode 100644 index 0000000000..24ec65fb47 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbbackingstore.cpp @@ -0,0 +1,284 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbbackingstore.h" + +#include "qxcbconnection.h" +#include "qxcbscreen.h" +#include "qxcbwindow.h" + +#include +#include + +#include +#include + +#include +#include + +#include +#include + +class QXcbShmImage : public QXcbObject +{ +public: + QXcbShmImage(QXcbScreen *connection, const QSize &size, uint depth, QImage::Format format); + ~QXcbShmImage() { destroy(); } + + QImage *image() { return &m_qimage; } + QSize size() const { return m_qimage.size(); } + + void put(xcb_window_t window, const QPoint &dst, const QRect &source); + void preparePaint(const QRegion ®ion); + +private: + void destroy(); + + xcb_shm_segment_info_t m_shm_info; + + xcb_image_t *m_xcb_image; + + QImage m_qimage; + + xcb_gcontext_t m_gc; + xcb_window_t m_gc_window; + + QRegion m_dirty; +}; + +QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QImage::Format format) + : QXcbObject(screen->connection()) + , m_gc(0) + , m_gc_window(0) +{ + Q_XCB_NOOP(connection()); + m_xcb_image = xcb_image_create_native(xcb_connection(), + size.width(), + size.height(), + XCB_IMAGE_FORMAT_Z_PIXMAP, + depth, + 0, + ~0, + 0); + + const int segmentSize = m_xcb_image->stride * m_xcb_image->height; + if (!segmentSize) + return; + + int id = shmget(IPC_PRIVATE, segmentSize, IPC_CREAT | 0777); + if (id == -1) + qWarning("QXcbShmImage: shmget() failed (%d) for size %d (%dx%d)", + errno, segmentSize, size.width(), size.height()); + else + m_shm_info.shmid = id; + m_shm_info.shmaddr = m_xcb_image->data = (quint8 *)shmat (m_shm_info.shmid, 0, 0); + m_shm_info.shmseg = xcb_generate_id(xcb_connection()); + + xcb_generic_error_t *error = xcb_request_check(xcb_connection(), xcb_shm_attach_checked(xcb_connection(), m_shm_info.shmseg, m_shm_info.shmid, false)); + if (error) { + qWarning() << "QXcbBackingStore: Unable to attach to shared memory segment"; + free(error); + } + + if (shmctl(m_shm_info.shmid, IPC_RMID, 0) == -1) + qWarning() << "QXcbBackingStore: Error while marking the shared memory segment to be destroyed"; + + m_qimage = QImage( (uchar*) m_xcb_image->data, m_xcb_image->width, m_xcb_image->height, m_xcb_image->stride, format); +} + +void QXcbShmImage::destroy() +{ + const int segmentSize = m_xcb_image ? (m_xcb_image->stride * m_xcb_image->height) : 0; + if (segmentSize) + Q_XCB_CALL(xcb_shm_detach(xcb_connection(), m_shm_info.shmseg)); + + xcb_image_destroy(m_xcb_image); + + if (segmentSize) { + shmdt(m_shm_info.shmaddr); + shmctl(m_shm_info.shmid, IPC_RMID, 0); + } + + if (m_gc) + Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc)); +} + +void QXcbShmImage::put(xcb_window_t window, const QPoint &target, const QRect &source) +{ + Q_XCB_NOOP(connection()); + if (m_gc_window != window) { + if (m_gc) + Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc)); + + m_gc = xcb_generate_id(xcb_connection()); + Q_XCB_CALL(xcb_create_gc(xcb_connection(), m_gc, window, 0, 0)); + + m_gc_window = window; + } + + Q_XCB_NOOP(connection()); + xcb_image_shm_put(xcb_connection(), + window, + m_gc, + m_xcb_image, + m_shm_info, + source.x(), + source.y(), + target.x(), + target.y(), + source.width(), + source.height(), + false); + Q_XCB_NOOP(connection()); + + m_dirty = m_dirty | source; + + xcb_flush(xcb_connection()); + Q_XCB_NOOP(connection()); +} + +void QXcbShmImage::preparePaint(const QRegion ®ion) +{ + // to prevent X from reading from the image region while we're writing to it + if (m_dirty.intersects(region)) { + connection()->sync(); + m_dirty = QRegion(); + } +} + +QXcbBackingStore::QXcbBackingStore(QWindow *window) + : QPlatformBackingStore(window) + , m_image(0) + , m_syncingResize(false) +{ + QXcbScreen *screen = static_cast(QPlatformScreen::platformScreenForWindow(window)); + setConnection(screen->connection()); +} + +QXcbBackingStore::~QXcbBackingStore() +{ + delete m_image; +} + +QPaintDevice *QXcbBackingStore::paintDevice() +{ + return m_image->image(); +} + +void QXcbBackingStore::beginPaint(const QRegion ®ion) +{ + m_image->preparePaint(region); + +#if 0 + if (m_image->image()->hasAlphaChannel()) { + QPainter p(m_image->image()); + p.setCompositionMode(QPainter::CompositionMode_Source); + const QVector rects = region.rects(); + const QColor blank = Qt::transparent; + for (QVector::const_iterator it = rects.begin(); it != rects.end(); ++it) { + p.fillRect(*it, blank); + } + } +#endif +} + +void QXcbBackingStore::endPaint(const QRegion &) +{ +} + +void QXcbBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +{ + QRect bounds = region.boundingRect(); + + if (!m_image || m_image->size().isEmpty()) + return; + + Q_XCB_NOOP(connection()); + + QXcbWindow *platformWindow = static_cast(window->handle()); + + QVector rects = region.rects(); + for (int i = 0; i < rects.size(); ++i) + m_image->put(platformWindow->xcb_window(), rects.at(i).topLeft(), rects.at(i).translated(offset)); + + Q_XCB_NOOP(connection()); + + if (m_syncingResize) { + xcb_flush(xcb_connection()); + connection()->sync(); + m_syncingResize = false; + platformWindow->updateSyncRequestCounter(); + } +} + +void QXcbBackingStore::resize(const QSize &size, const QRegion &) +{ + if (m_image && size == m_image->size()) + return; + + Q_XCB_NOOP(connection()); + + QXcbScreen *screen = static_cast(QPlatformScreen::platformScreenForWindow(window())); + QXcbWindow* win = static_cast(window()->handle()); + + delete m_image; + m_image = new QXcbShmImage(screen, size, win->depth(), win->format()); + Q_XCB_NOOP(connection()); + + m_syncingResize = true; +} + +extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset); + +bool QXcbBackingStore::scroll(const QRegion &area, int dx, int dy) +{ + if (!m_image || m_image->image()->isNull()) + return false; + + m_image->preparePaint(area); + + const QVector rects = area.rects(); + for (int i = 0; i < rects.size(); ++i) + qt_scrollRectInImage(*m_image->image(), rects.at(i), QPoint(dx, dy)); + + return true; +} + diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.h b/src/plugins/platforms/xcb/qxcbbackingstore.h new file mode 100644 index 0000000000..db94d26b09 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbbackingstore.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBBACKINGSTORE_H +#define QXCBBACKINGSTORE_H + +#include + +#include + +#include "qxcbobject.h" + +class QXcbShmImage; + +class QXcbBackingStore : public QXcbObject, public QPlatformBackingStore +{ +public: + QXcbBackingStore(QWindow *widget); + ~QXcbBackingStore(); + + QPaintDevice *paintDevice(); + void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); + void resize(const QSize &size, const QRegion &staticContents); + bool scroll(const QRegion &area, int dx, int dy); + + void beginPaint(const QRegion &); + void endPaint(const QRegion &); + +private: + QXcbShmImage *m_image; + bool m_syncingResize; +}; + +#endif diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index a07a5a544e..72d0036a3c 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -43,7 +43,7 @@ #include "qxcbconnection.h" #include "qxcbscreen.h" #include "qxcbwindow.h" -#include "qxcbwindowsurface.h" +#include "qxcbbackingstore.h" #include "qxcbnativeinterface.h" #include "qxcbclipboard.h" #include "qxcbdrag.h" @@ -114,10 +114,9 @@ QPlatformGLContext *QXcbIntegration::createPlatformGLContext(const QGuiGLFormat #endif } -QWindowSurface *QXcbIntegration::createWindowSurface(QWindow *window, WId winId) const +QPlatformBackingStore *QXcbIntegration::createPlatformBackingStore(QWindow *window) const { - Q_UNUSED(winId); - return new QXcbWindowSurface(window); + return new QXcbBackingStore(window); } QList QXcbIntegration::screens() const diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h index d931e2a787..5837be1148 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.h +++ b/src/plugins/platforms/xcb/qxcbintegration.h @@ -59,7 +59,7 @@ public: QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const; - QWindowSurface *createWindowSurface(QWindow *window, WId winId) const; + QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QList screens() const; void moveToScreen(QWindow *window, int screen); diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 3cf78d00c3..547a93be0b 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -56,8 +56,8 @@ #include #include -#include +#include #include #include @@ -1053,12 +1053,8 @@ QPlatformGLSurface *QXcbWindow::createGLSurface() const void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event) { - QWindowSurface *surface = window()->surface(); - if (surface) { - QRect rect(event->x, event->y, event->width, event->height); - - QWindowSystemInterface::handleExposeEvent(window(), rect); - } + QRect rect(event->x, event->y, event->width, event->height); + QWindowSystemInterface::handleExposeEvent(window(), rect); } void QXcbWindow::handleClientMessageEvent(const xcb_client_message_event_t *event) diff --git a/src/plugins/platforms/xcb/qxcbwindowsurface.cpp b/src/plugins/platforms/xcb/qxcbwindowsurface.cpp deleted file mode 100644 index 63378515cc..0000000000 --- a/src/plugins/platforms/xcb/qxcbwindowsurface.cpp +++ /dev/null @@ -1,282 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qxcbwindowsurface.h" - -#include "qxcbconnection.h" -#include "qxcbscreen.h" -#include "qxcbwindow.h" - -#include -#include - -#include -#include - -#include -#include - -#include -#include - -class QXcbShmImage : public QXcbObject -{ -public: - QXcbShmImage(QXcbScreen *connection, const QSize &size, uint depth, QImage::Format format); - ~QXcbShmImage() { destroy(); } - - QImage *image() { return &m_qimage; } - - void put(xcb_window_t window, const QPoint &dst, const QRect &source); - void preparePaint(const QRegion ®ion); - -private: - void destroy(); - - xcb_shm_segment_info_t m_shm_info; - - xcb_image_t *m_xcb_image; - - QImage m_qimage; - - xcb_gcontext_t m_gc; - xcb_window_t m_gc_window; - - QRegion m_dirty; -}; - -QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QImage::Format format) - : QXcbObject(screen->connection()) - , m_gc(0) - , m_gc_window(0) -{ - Q_XCB_NOOP(connection()); - m_xcb_image = xcb_image_create_native(xcb_connection(), - size.width(), - size.height(), - XCB_IMAGE_FORMAT_Z_PIXMAP, - depth, - 0, - ~0, - 0); - - const int segmentSize = m_xcb_image->stride * m_xcb_image->height; - if (!segmentSize) - return; - - int id = shmget(IPC_PRIVATE, segmentSize, IPC_CREAT | 0777); - if (id == -1) - qWarning("QXcbShmImage: shmget() failed (%d) for size %d (%dx%d)", - errno, segmentSize, size.width(), size.height()); - else - m_shm_info.shmid = id; - m_shm_info.shmaddr = m_xcb_image->data = (quint8 *)shmat (m_shm_info.shmid, 0, 0); - m_shm_info.shmseg = xcb_generate_id(xcb_connection()); - - xcb_generic_error_t *error = xcb_request_check(xcb_connection(), xcb_shm_attach_checked(xcb_connection(), m_shm_info.shmseg, m_shm_info.shmid, false)); - if (error) { - qWarning() << "QXcbWindowSurface: Unable to attach to shared memory segment"; - free(error); - } - - if (shmctl(m_shm_info.shmid, IPC_RMID, 0) == -1) - qWarning() << "QXcbWindowSurface: Error while marking the shared memory segment to be destroyed"; - - m_qimage = QImage( (uchar*) m_xcb_image->data, m_xcb_image->width, m_xcb_image->height, m_xcb_image->stride, format); -} - -void QXcbShmImage::destroy() -{ - const int segmentSize = m_xcb_image ? (m_xcb_image->stride * m_xcb_image->height) : 0; - if (segmentSize) - Q_XCB_CALL(xcb_shm_detach(xcb_connection(), m_shm_info.shmseg)); - - xcb_image_destroy(m_xcb_image); - - if (segmentSize) { - shmdt(m_shm_info.shmaddr); - shmctl(m_shm_info.shmid, IPC_RMID, 0); - } - - if (m_gc) - Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc)); -} - -void QXcbShmImage::put(xcb_window_t window, const QPoint &target, const QRect &source) -{ - Q_XCB_NOOP(connection()); - if (m_gc_window != window) { - if (m_gc) - Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc)); - - m_gc = xcb_generate_id(xcb_connection()); - Q_XCB_CALL(xcb_create_gc(xcb_connection(), m_gc, window, 0, 0)); - - m_gc_window = window; - } - - Q_XCB_NOOP(connection()); - xcb_image_shm_put(xcb_connection(), - window, - m_gc, - m_xcb_image, - m_shm_info, - source.x(), - source.y(), - target.x(), - target.y(), - source.width(), - source.height(), - false); - Q_XCB_NOOP(connection()); - - m_dirty = m_dirty | source; - - xcb_flush(xcb_connection()); - Q_XCB_NOOP(connection()); -} - -void QXcbShmImage::preparePaint(const QRegion ®ion) -{ - // to prevent X from reading from the image region while we're writing to it - if (m_dirty.intersects(region)) { - connection()->sync(); - m_dirty = QRegion(); - } -} - -QXcbWindowSurface::QXcbWindowSurface(QWindow *window, bool setDefaultSurface) - : QWindowSurface(window, setDefaultSurface) - , m_image(0) - , m_syncingResize(false) -{ - QXcbScreen *screen = static_cast(QPlatformScreen::platformScreenForWindow(window)); - setConnection(screen->connection()); -} - -QXcbWindowSurface::~QXcbWindowSurface() -{ - delete m_image; -} - -QPaintDevice *QXcbWindowSurface::paintDevice() -{ - return m_image->image(); -} - -void QXcbWindowSurface::beginPaint(const QRegion ®ion) -{ - m_image->preparePaint(region); - - if (m_image->image()->hasAlphaChannel()) { - QPainter p(m_image->image()); - p.setCompositionMode(QPainter::CompositionMode_Source); - const QVector rects = region.rects(); - const QColor blank = Qt::transparent; - for (QVector::const_iterator it = rects.begin(); it != rects.end(); ++it) { - p.fillRect(*it, blank); - } - } -} - -void QXcbWindowSurface::endPaint(const QRegion &) -{ -} - -void QXcbWindowSurface::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) -{ - QRect bounds = region.boundingRect(); - - if (size().isEmpty() || !geometry().contains(bounds)) - return; - - Q_XCB_NOOP(connection()); - - QXcbWindow *platformWindow = static_cast(window->handle()); - - QVector rects = region.rects(); - for (int i = 0; i < rects.size(); ++i) - m_image->put(platformWindow->xcb_window(), rects.at(i).topLeft(), rects.at(i).translated(offset)); - - Q_XCB_NOOP(connection()); - - if (m_syncingResize) { - xcb_flush(xcb_connection()); - connection()->sync(); - m_syncingResize = false; - platformWindow->updateSyncRequestCounter(); - } -} - -void QXcbWindowSurface::resize(const QSize &size) -{ - if (size == QWindowSurface::size()) - return; - - Q_XCB_NOOP(connection()); - QWindowSurface::resize(size); - - QXcbScreen *screen = static_cast(QPlatformScreen::platformScreenForWindow(window())); - QXcbWindow* win = static_cast(window()->handle()); - - delete m_image; - m_image = new QXcbShmImage(screen, size, win->depth(), win->format()); - Q_XCB_NOOP(connection()); - - m_syncingResize = true; -} - -extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset); - -bool QXcbWindowSurface::scroll(const QRegion &area, int dx, int dy) -{ - if (!m_image || m_image->image()->isNull()) - return false; - - m_image->preparePaint(area); - - const QVector rects = area.rects(); - for (int i = 0; i < rects.size(); ++i) - qt_scrollRectInImage(*m_image->image(), rects.at(i), QPoint(dx, dy)); - - return true; -} - diff --git a/src/plugins/platforms/xcb/qxcbwindowsurface.h b/src/plugins/platforms/xcb/qxcbwindowsurface.h deleted file mode 100644 index 8f401d94a3..0000000000 --- a/src/plugins/platforms/xcb/qxcbwindowsurface.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QXCBWINDOWSURFACE_H -#define QXCBWINDOWSURFACE_H - -#include - -#include - -#include "qxcbobject.h" - -class QXcbShmImage; - -class QXcbWindowSurface : public QXcbObject, public QWindowSurface -{ -public: - QXcbWindowSurface(QWindow *widget, bool setDefaultSurface = true); - ~QXcbWindowSurface(); - - QPaintDevice *paintDevice(); - void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); - void resize(const QSize &size); - bool scroll(const QRegion &area, int dx, int dy); - - void beginPaint(const QRegion &); - void endPaint(const QRegion &); - -private: - QXcbShmImage *m_image; - bool m_syncingResize; -}; - -#endif diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro index e5d9b98bd0..8cf7ec4aff 100644 --- a/src/plugins/platforms/xcb/xcb.pro +++ b/src/plugins/platforms/xcb/xcb.pro @@ -14,7 +14,7 @@ SOURCES = \ qxcbdrag.cpp \ qxcbscreen.cpp \ qxcbwindow.cpp \ - qxcbwindowsurface.cpp \ + qxcbbackingstore.cpp \ qxcbwmsupport.cpp \ main.cpp \ qxcbnativeinterface.cpp \ @@ -31,7 +31,7 @@ HEADERS = \ qxcbobject.h \ qxcbscreen.h \ qxcbwindow.h \ - qxcbwindowsurface.h \ + qxcbbackingstore.h \ qxcbwmsupport.h \ qxcbnativeinterface.h \ qxcbcursor.h \ -- cgit v1.2.3