Add wayland mac readback implementation.

bb10
Morten Sorvig 2011-06-06 12:39:45 +02:00
parent 0058f00b64
commit bebda38eaf
7 changed files with 527 additions and 0 deletions

View File

@ -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 <QtGui/QGuiGLContext>
#include <QtCore/QDebug>
#include <OpenGL/OpenGL.h>
#include <OpenGL/glext.h>
#include <QtPlatformSupport/private/cglconvenience_p.h>
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<QWaylandReadbackCGLWindow *>(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<QWaylandReadbackCGLWindow *>(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<uchar *>(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<uchar *>(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);
}

View File

@ -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 <QPlatformGLContext>
#include "qwaylandreadbackcglintegration.h"
#include <OpenGL/OpenGL.h>
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

View File

@ -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 <QtCore/QDebug>
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;
}

View File

@ -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 <QtCore/QTextStream>
#include <QtCore/QDataStream>
#include <QtCore/QMetaType>
#include <QtCore/QVariant>
#include <QtGui/QWindow>
#include <X11/Xlib.h>
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

View File

@ -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 <OpenGL/OpenGL.h>
#include <OpenGL/glext.h>
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);
}

View File

@ -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 <OpenGL/OpenGL.h>
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

View File

@ -0,0 +1,10 @@
HEADERS += \
$$PWD/qwaylandreadbackcglintegration.h \
$$PWD/qwaylandreadbackcglwindow.h \
$$PWD/qwaylandreadbackcglcontext.h
SOURCES += \
$$PWD/qwaylandreadbackcglintegration.cpp \
$$PWD/qwaylandreadbackcglwindow.cpp \
$$PWD/qwaylandreadbackcglcontext.cpp