From bebda38eaf18c282ba64a59033f2b611c1043d1f Mon Sep 17 00:00:00 2001 From: Morten Sorvig Date: Mon, 6 Jun 2011 12:39:45 +0200 Subject: [PATCH] Add wayland mac readback implementation. --- .../readback_cgl/qwaylandreadbackcglcontext.cpp | 116 +++++++++++++++++++++ .../readback_cgl/qwaylandreadbackcglcontext.h | 72 +++++++++++++ .../qwaylandreadbackcglintegration.cpp | 82 +++++++++++++++ .../readback_cgl/qwaylandreadbackcglintegration.h | 71 +++++++++++++ .../readback_cgl/qwaylandreadbackcglwindow.cpp | 106 +++++++++++++++++++ .../readback_cgl/qwaylandreadbackcglwindow.h | 70 +++++++++++++ .../gl_integration/readback_cgl/readback_cgl.pri | 10 ++ 7 files changed, 527 insertions(+) create mode 100644 src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglcontext.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglcontext.h create mode 100644 src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglintegration.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglintegration.h create mode 100644 src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglwindow.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglwindow.h create mode 100644 src/plugins/platforms/wayland/gl_integration/readback_cgl/readback_cgl.pri diff --git a/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglcontext.cpp b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglcontext.cpp new file mode 100644 index 0000000..7f21f2e --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglcontext.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** 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 "qwaylandreadbackcglcontext.h" + +#include "qwaylandshmbackingstore.h" +#include "qwaylandreadbackcglwindow.h" + +#include +#include + +#include +#include + +#include + +QWaylandReadbackCGLContext::QWaylandReadbackCGLContext(QPlatformGLContext *share) + : QPlatformGLContext() +{ + Q_UNUSED(share); + m_glContext = qcgl_createGlContext(); +} + +QSurfaceFormat QWaylandReadbackCGLContext::format() const +{ + return qcgl_surfaceFormat(); +} + +bool QWaylandReadbackCGLContext::makeCurrent(QPlatformSurface *surface) +{ + QWaylandReadbackCGLWindow *window = static_cast(surface); + CGLSetPBuffer(m_glContext, window->pixelBuffer(), 0, 0, 0); + CGLSetCurrentContext(m_glContext); + return true; +} + +void QWaylandReadbackCGLContext::doneCurrent() +{ + CGLSetCurrentContext(0); +} + +void QWaylandReadbackCGLContext::swapBuffers(QPlatformSurface *surface) +{ + Q_UNUSED(surface); + + if (QGuiGLContext::currentContext()->handle() != this) { + makeCurrent(surface); + } + CGLFlushDrawable(m_glContext); + + QWaylandReadbackCGLWindow *window = static_cast(surface); + + QSize size = window->geometry().size(); + + QImage img(size,QImage::Format_ARGB32); + img.fill(Qt::red); + const uchar *constBits = img.bits(); + void *pixels = const_cast(constBits); + +// glReadPixels(0,0, size.width(), size.height(), GL_RGBA,GL_UNSIGNED_BYTE, pixels); +// img = img.mirrored(); +// qgl_byteSwapImage(img,GL_UNSIGNED_INT_8_8_8_8_REV); + + constBits = img.bits(); + + const uchar *constDstBits = window->buffer(); + uchar *dstBits = const_cast(constDstBits); + memcpy(dstBits,constBits,(img.width()*4) * img.height()); + + window->damage(QRect(QPoint(0,0),size)); + window->waitForFrameSync(); +} + +void (*QWaylandReadbackCGLContext::getProcAddress(const QByteArray &procName)) () +{ + return qcgl_getProcAddress(procName); +} + diff --git a/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglcontext.h b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglcontext.h new file mode 100644 index 0000000..7f727ae --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglcontext.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 QWAYLANDREADBACKCGLCONTEXT_H +#define QWAYLANDREADBACKCGLCONTEXT_H + +#include + +#include "qwaylandreadbackcglintegration.h" + +#include + +class QWaylandReadbackCGLWindow; +class QWaylandShmBuffer; + +class QWaylandReadbackCGLContext : public QPlatformGLContext +{ +public: + QWaylandReadbackCGLContext(QPlatformGLContext *share); + + QSurfaceFormat format() const; + + bool makeCurrent(QPlatformSurface *surface); + void doneCurrent(); + void swapBuffers(QPlatformSurface *surface); + void (*getProcAddress(const QByteArray &procName)) (); + + void geometryChanged(); + +private: + CGLContextObj m_glContext; +}; + +#endif // QWAYLANDREADBACKCGLCONTEXT_H diff --git a/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglintegration.cpp b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglintegration.cpp new file mode 100644 index 0000000..c9cc7b4 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglintegration.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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 "qwaylandreadbackcglintegration.h" +#include "qwaylandreadbackcglcontext.h" +#include "qwaylandreadbackcglwindow.h" + +#include + +QWaylandGLIntegration * QWaylandGLIntegration::createGLIntegration(QWaylandDisplay *waylandDisplay) +{ + return new QWaylandReadbackCGLIntegration(waylandDisplay); +} + +QWaylandReadbackCGLIntegration::QWaylandReadbackCGLIntegration(QWaylandDisplay * waylandDispaly) + : QWaylandGLIntegration() + , mWaylandDisplay(waylandDispaly) +{ + qDebug() << "Using Readback-CGL"; +} + +QWaylandReadbackCGLIntegration::~QWaylandReadbackCGLIntegration() +{ + +} + +void QWaylandReadbackCGLIntegration::initialize() +{ +} + +QWaylandWindow * QWaylandReadbackCGLIntegration::createEglWindow(QWindow *window) +{ + return new QWaylandReadbackCGLWindow(window,this); +} + +QPlatformGLContext *QWaylandReadbackCGLIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const +{ + return new QWaylandReadbackCGLContext(share); +} + +QWaylandDisplay * QWaylandReadbackCGLIntegration::waylandDisplay() const +{ + return mWaylandDisplay; +} diff --git a/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglintegration.h b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglintegration.h new file mode 100644 index 0000000..63b95f5 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglintegration.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 QWAYLANDREADBACKGLXINTEGRATION_H +#define QWAYLANDREADBACKGLXINTEGRATION_H + +#include "gl_integration/qwaylandglintegration.h" + +#include +#include +#include +#include +#include + +#include + +class QWaylandReadbackCGLIntegration : public QWaylandGLIntegration +{ +public: + QWaylandReadbackCGLIntegration(QWaylandDisplay * waylandDispaly); + ~QWaylandReadbackCGLIntegration(); + + void initialize(); + + QWaylandWindow *createEglWindow(QWindow *window); + QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const; + QWaylandDisplay *waylandDisplay() const; + +private: + QWaylandDisplay *mWaylandDisplay; +}; + +#endif // QWAYLANDREADBACKGLXINTEGRATION_H diff --git a/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglwindow.cpp b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglwindow.cpp new file mode 100644 index 0000000..9e7f852 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglwindow.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** 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 "qwaylandreadbackcglwindow.h" +#include "qwaylandshmbackingstore.h" + +#include +#include + +QWaylandReadbackCGLWindow::QWaylandReadbackCGLWindow(QWindow *window, QWaylandReadbackCGLIntegration *cglIntegration) + : QWaylandShmWindow(window) + , m_CglIntegration(cglIntegration) + , mContext(0) + , m_buffer(0) + , m_pixelBuffer(0) +{ +} + +QWaylandWindow::WindowType QWaylandReadbackCGLWindow::windowType() const +{ + //yeah. this type needs a new name + return QWaylandWindow::Egl; +} + + +void QWaylandReadbackCGLWindow::setGeometry(const QRect &rect) +{ + QWaylandShmWindow::setGeometry(rect); + + if (m_buffer) { + delete m_buffer; + m_buffer = 0; + + CGLDestroyPBuffer(m_pixelBuffer); + m_pixelBuffer = 0; + } +} + +CGLPBufferObj QWaylandReadbackCGLWindow::pixelBuffer() +{ + if (!m_pixelBuffer) + createSurface(); + + return m_pixelBuffer; +} + +uchar *QWaylandReadbackCGLWindow::buffer() +{ + return m_buffer->image()->bits(); +} + +void QWaylandReadbackCGLWindow::createSurface() +{ + QSize size(geometry().size()); + if (size.isEmpty()) { + //QGLWidget wants a context for a window without geometry + size = QSize(1,1); + } + + waitForFrameSync(); + + CGLCreatePBuffer(size.width(), size.height(), GL_TEXTURE_RECTANGLE_ARB, GL_BGRA, 0, &m_pixelBuffer); + + delete m_buffer; + m_buffer = new QWaylandShmBuffer(m_CglIntegration->waylandDisplay(),size,QImage::Format_ARGB32); + attach(m_buffer); +} + diff --git a/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglwindow.h b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglwindow.h new file mode 100644 index 0000000..0598cf9 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/readback_cgl/qwaylandreadbackcglwindow.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 QWAYLANDREADBACKGLXWINDOW_H +#define QWAYLANDREADBACKGLXWINDOW_H + +#include "qwaylandshmwindow.h" +#include "qwaylandreadbackcglintegration.h" +#include "qwaylandreadbackcglcontext.h" + +#include + +class QWaylandReadbackCGLWindow : public QWaylandShmWindow +{ +public: + QWaylandReadbackCGLWindow(QWindow *window, QWaylandReadbackCGLIntegration *cglIntegration); + WindowType windowType() const; + + void setGeometry(const QRect &rect); + CGLPBufferObj pixelBuffer(); + uchar *buffer(); +private: + void createSurface(); + + QWaylandReadbackCGLIntegration *m_CglIntegration; + QWaylandReadbackCGLContext *mContext; + + QWaylandShmBuffer *m_buffer; + CGLPBufferObj m_pixelBuffer; +}; + +#endif // QWAYLANDREADBACKGLXWINDOW_H diff --git a/src/plugins/platforms/wayland/gl_integration/readback_cgl/readback_cgl.pri b/src/plugins/platforms/wayland/gl_integration/readback_cgl/readback_cgl.pri new file mode 100644 index 0000000..91cb90a --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/readback_cgl/readback_cgl.pri @@ -0,0 +1,10 @@ +HEADERS += \ + $$PWD/qwaylandreadbackcglintegration.h \ + $$PWD/qwaylandreadbackcglwindow.h \ + $$PWD/qwaylandreadbackcglcontext.h + +SOURCES += \ + $$PWD/qwaylandreadbackcglintegration.cpp \ + $$PWD/qwaylandreadbackcglwindow.cpp \ + $$PWD/qwaylandreadbackcglcontext.cpp + -- 2.7.4