Remove unused kms plugin

The old kms plugin has been replaced by EGLFS's KMS backend. The EGLFS
backend is smaller and has more features.

The kms plugin cannot be built automatically since Qt 5.5 and is
therefore also not tested for changes in QPA API by the CI. Therefore
removing the plugin from the tree should not be a regression from the
previous release.

Change-Id: Icb9ea8c4a5d6421397a2e3f2e2195fb6bfad2293
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
This commit is contained in:
Louai Al-Khanji 2015-08-24 11:44:58 +03:00
parent 55bc1ddc76
commit aab5698dd9
19 changed files with 0 additions and 2006 deletions

View File

@ -1,3 +0,0 @@
{
"Keys": [ "kms" ]
}

View File

@ -1,37 +0,0 @@
TARGET = qkms
PLUGIN_TYPE = platforms
PLUGIN_CLASS_NAME = QKmsIntegrationPlugin
!equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = -
load(qt_plugin)
QT += core-private gui-private platformsupport-private
qtHaveModule(opengl):QT += opengl-private
DEFINES += MESA_EGL_NO_X11_HEADERS __GBM__
CONFIG += link_pkgconfig egl qpa/genericunixfontdatabase
PKGCONFIG += libdrm libudev egl gbm glesv2
SOURCES = main.cpp \
qkmsintegration.cpp \
qkmsscreen.cpp \
qkmscontext.cpp \
qkmswindow.cpp \
qkmscursor.cpp \
qkmsdevice.cpp \
qkmsbackingstore.cpp \
qkmsnativeinterface.cpp
HEADERS = qkmsintegration.h \
qkmsscreen.h \
qkmscontext.h \
qkmswindow.h \
qkmscursor.h \
qkmsdevice.h \
qkmsbackingstore.h \
qkmsnativeinterface.h
OTHER_FILES += \
kms.json

View File

@ -1,58 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <qpa/qplatformintegrationplugin.h>
#include "qkmsintegration.h"
QT_BEGIN_NAMESPACE
class QKmsIntegrationPlugin : public QPlatformIntegrationPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID QPlatformIntegrationFactoryInterface_iid FILE "kms.json")
public:
QPlatformIntegration *create(const QString&, const QStringList&) Q_DECL_OVERRIDE;
};
QPlatformIntegration *QKmsIntegrationPlugin::create(const QString& system, const QStringList& paramList)
{
Q_UNUSED(paramList);
if (!system.compare(QLatin1String("kms"), Qt::CaseInsensitive))
return new QKmsIntegration;
return 0;
}
QT_END_NAMESPACE
#include "main.moc"

View File

@ -1,217 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qkmsbackingstore.h"
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLShaderProgram>
#include <QtGui/QScreen>
QT_BEGIN_NAMESPACE
QKmsBackingStore::QKmsBackingStore(QWindow *window)
: QPlatformBackingStore(window)
, m_context(new QOpenGLContext)
, m_texture(0)
, m_program(0)
, m_initialized(false)
{
m_context->setFormat(window->requestedFormat());
m_context->setScreen(window->screen());
m_context->create();
}
QKmsBackingStore::~QKmsBackingStore()
{
delete m_program;
if (m_texture)
glDeleteTextures(1, &m_texture);
delete m_context;
}
QPaintDevice *QKmsBackingStore::paintDevice()
{
return &m_image;
}
void QKmsBackingStore::beginPaint(const QRegion &rgn)
{
m_dirty |= rgn;
}
void QKmsBackingStore::flush(QWindow *window, const QRegion &region, const QPoint &offset)
{
Q_UNUSED(region)
Q_UNUSED(offset)
m_context->makeCurrent(window);
if (!m_initialized) {
initializeOpenGLFunctions();
m_initialized = true;
}
if (!m_program) {
static const char *textureVertexProgram =
"attribute highp vec2 vertexCoordEntry;\n"
"attribute highp vec2 textureCoordEntry;\n"
"varying highp vec2 textureCoord;\n"
"void main() {\n"
" textureCoord = textureCoordEntry;\n"
" gl_Position = vec4(vertexCoordEntry, 0.0, 1.0);\n"
"}\n";
static const char *textureFragmentProgram =
"uniform sampler2D texture;\n"
"varying highp vec2 textureCoord;\n"
"void main() {\n"
" gl_FragColor = texture2D(texture, textureCoord).bgra;\n"
"}\n";
m_program = new QOpenGLShaderProgram;
m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, textureVertexProgram);
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, textureFragmentProgram);
m_program->bindAttributeLocation("vertexCoordEntry", 0);
m_program->bindAttributeLocation("textureCoordEntry", 1);
m_program->link();
}
m_program->bind();
QRectF r = window->geometry();
QRectF sr = window->screen()->geometry();
GLfloat x1 = (r.left() / sr.width()) * 2 - 1;
GLfloat x2 = (r.right() / sr.width()) * 2 - 1;
GLfloat y1 = -1 * ((r.top() / sr.height()) * 2 - 1);
GLfloat y2 = -1 * ((r.bottom() / sr.height()) * 2 - 1);
const GLfloat vertexCoordinates[] = {
x1, y1,
x2, y1,
x2, y2,
x1, y2
};
const GLfloat textureCoordinates[] = {
0, 0,
1, 0,
1, 1,
0, 1
};
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertexCoordinates);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, textureCoordinates);
glBindTexture(GL_TEXTURE_2D, m_texture);
if (!m_dirty.isNull()) {
QRect imageRect = m_image.rect();
QRegion fixed;
Q_FOREACH (const QRect &rect, m_dirty.rects()) {
// intersect with image rect to be sure
QRect r = imageRect & rect;
// if the rect is wide enough it's cheaper to just
// extend it instead of doing an image copy
if (r.width() >= imageRect.width() / 2) {
r.setX(0);
r.setWidth(imageRect.width());
}
fixed |= r;
}
Q_FOREACH (const QRect &rect, fixed.rects()) {
// if the sub-rect is full-width we can pass the image data directly to
// OpenGL instead of copying, since there's no gap between scanlines
if (rect.width() == imageRect.width()) {
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, rect.y(),
rect.width(), rect.height(),
GL_RGBA, GL_UNSIGNED_BYTE,
m_image.constScanLine(rect.y()));
} else {
glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(),
rect.width(), rect.height(),
GL_RGBA, GL_UNSIGNED_BYTE,
m_image.copy(rect).constBits());
}
}
m_dirty = QRegion();
}
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
m_program->release();
glBindTexture(GL_TEXTURE_2D, 0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
m_context->swapBuffers(window);
m_context->doneCurrent();
}
void QKmsBackingStore::resize(const QSize &size, const QRegion &staticContents)
{
Q_UNUSED(staticContents)
m_image = QImage(size, QImage::Format_RGB32);
m_context->makeCurrent(window());
if (!m_initialized) {
initializeOpenGLFunctions();
m_initialized = true;
}
if (m_texture)
glDeleteTextures(1, &m_texture);
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(),
0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
}
QT_END_NAMESPACE

View File

@ -1,72 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QBACKINGSTORE_KMS_H
#define QBACKINGSTORE_KMS_H
#include <qpa/qplatformbackingstore.h>
#include <QtGui/QOpenGLFunctions>
#include <QImage>
QT_BEGIN_NAMESPACE
class QOpenGLContext;
class QOpenGLShaderProgram;
class QKmsBackingStore : public QPlatformBackingStore, public QOpenGLFunctions
{
public:
QKmsBackingStore(QWindow *window);
~QKmsBackingStore();
QPaintDevice *paintDevice() Q_DECL_OVERRIDE;
void beginPaint(const QRegion &) Q_DECL_OVERRIDE;
void flush(QWindow *window, const QRegion &region, const QPoint &offset) Q_DECL_OVERRIDE;
void resize(const QSize &size, const QRegion &staticContents) Q_DECL_OVERRIDE;
QImage toImage() const Q_DECL_OVERRIDE { return m_image; }
private:
QOpenGLContext *m_context;
QImage m_image;
uint m_texture;
QOpenGLShaderProgram *m_program;
QRegion m_dirty;
bool m_initialized;
};
QT_END_NAMESPACE
#endif

View File

@ -1,136 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qkmsscreen.h"
#include "qkmsdevice.h"
#include "qkmscontext.h"
#include "qkmswindow.h"
#include "qkmsintegration.h"
#include <QtGui/QOpenGLContext>
#include <QtPlatformSupport/private/qeglconvenience_p.h>
QT_BEGIN_NAMESPACE
QKmsContext::QKmsContext(QOpenGLContext *context, QKmsDevice *device)
: m_device(device)
{
EGLDisplay display = m_device->eglDisplay();
EGLConfig config = q_configFromGLFormat(display, QKmsScreen::tweakFormat(context->format()));
m_format = q_glFormatFromConfig(display, config);
//Initialize EGLContext
static EGLint contextAttribs[] = {
EGL_CONTEXT_CLIENT_VERSION, context->format().majorVersion(),
EGL_NONE
};
eglBindAPI(EGL_OPENGL_ES_API);
EGLContext share = EGL_NO_CONTEXT;
if (context->shareContext())
share = static_cast<QKmsContext *>(context->shareContext()->handle())->eglContext();
m_eglContext = eglCreateContext(display, config, share, contextAttribs);
if (m_eglContext == EGL_NO_CONTEXT) {
qWarning("QKmsContext::QKmsContext(): eglError: %x, this: %p",
eglGetError(), this);
m_eglContext = 0;
}
}
bool QKmsContext::isValid() const
{
return m_eglContext != EGL_NO_CONTEXT;
}
bool QKmsContext::makeCurrent(QPlatformSurface *surface)
{
Q_ASSERT(surface->surface()->supportsOpenGL());
EGLDisplay display = m_device->eglDisplay();
EGLSurface eglSurface;
if (surface->surface()->surfaceClass() == QSurface::Window) {
QPlatformWindow *window = static_cast<QPlatformWindow *>(surface);
QKmsScreen *screen = static_cast<QKmsScreen *>(QPlatformScreen::platformScreenForWindow(window->window()));
eglSurface = screen->eglSurface();
screen->waitForPageFlipComplete();
} else {
eglSurface = static_cast<QKmsOffscreenWindow *>(surface)->surface();
}
bool ok = eglMakeCurrent(display, eglSurface, eglSurface, m_eglContext);
if (!ok)
qWarning("QKmsContext::makeCurrent(): eglError: %x, this: %p",
eglGetError(), this);
return true;
}
void QKmsContext::doneCurrent()
{
bool ok = eglMakeCurrent(m_device->eglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE,
EGL_NO_CONTEXT);
if (!ok)
qWarning("QKmsContext::doneCurrent(): eglError: %x, this: %p",
eglGetError(), this);
}
void QKmsContext::swapBuffers(QPlatformSurface *surface)
{
//Cast context to a window surface and get the screen the context
//is on and call swapBuffers on that screen.
QPlatformWindow *window = static_cast<QPlatformWindow *>(surface);
QKmsScreen *screen = static_cast<QKmsScreen *> (QPlatformScreen::platformScreenForWindow(window->window()));
screen->swapBuffers();
}
void (*QKmsContext::getProcAddress(const QByteArray &procName)) ()
{
return eglGetProcAddress(procName.data());
}
EGLContext QKmsContext::eglContext() const
{
return m_eglContext;
}
QSurfaceFormat QKmsContext::format() const
{
return m_format;
}
QT_END_NAMESPACE

View File

@ -1,71 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QKMSCONTEXT_H
#define QKMSCONTEXT_H
#include <qpa/qplatformopenglcontext.h>
#define EGL_EGLEXT_PROTOTYPES 1
#include <EGL/egl.h>
QT_BEGIN_NAMESPACE
class QKmsDevice;
class QKmsContext : public QPlatformOpenGLContext
{
public:
QKmsContext(QOpenGLContext *context, QKmsDevice *device);
bool makeCurrent(QPlatformSurface *surface) Q_DECL_OVERRIDE;
void doneCurrent() Q_DECL_OVERRIDE;
void swapBuffers(QPlatformSurface *surface) Q_DECL_OVERRIDE;
void (*getProcAddress(const QByteArray &procName)) () Q_DECL_OVERRIDE;
bool isValid() const Q_DECL_OVERRIDE;
QSurfaceFormat format() const Q_DECL_OVERRIDE;
EGLContext eglContext() const;
private:
EGLContext m_eglContext;
QSurfaceFormat m_format;
QKmsDevice *m_device;
};
QT_END_NAMESPACE
#endif // QKMSCONTEXT_H

View File

@ -1,116 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//#include <QDebug>
#include "qkmscursor.h"
#include "qkmsscreen.h"
#include "qkmsdevice.h"
QT_BEGIN_NAMESPACE
#ifndef DRM_CAP_CURSOR_WIDTH
#define DRM_CAP_CURSOR_WIDTH 0x8
#endif
#ifndef DRM_CAP_CURSOR_HEIGHT
#define DRM_CAP_CURSOR_HEIGHT 0x9
#endif
QKmsCursor::QKmsCursor(QKmsScreen *screen)
: m_screen(screen),
m_graphicsBufferManager(screen->device()->gbmDevice()),
m_cursorImage(new QPlatformCursorImage(0, 0, 0, 0, 0, 0)),
m_moved(false),
m_cursorSize(64, 64)
{
uint64_t value = 0;
if (!drmGetCap(m_screen->device()->fd(), DRM_CAP_CURSOR_WIDTH, &value))
m_cursorSize.setWidth(value);
if (!drmGetCap(m_screen->device()->fd(), DRM_CAP_CURSOR_HEIGHT, &value))
m_cursorSize.setHeight(value);
m_cursorBufferObject = gbm_bo_create(m_graphicsBufferManager, m_cursorSize.width(), m_cursorSize.height(),
GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE);
}
QKmsCursor::~QKmsCursor()
{
drmModeSetCursor(m_screen->device()->fd(), m_screen->crtcId(), 0, 0, 0);
gbm_bo_destroy(m_cursorBufferObject);
}
void QKmsCursor::pointerEvent(const QMouseEvent &event)
{
m_moved = true;
int status = drmModeMoveCursor(m_screen->device()->fd(),
m_screen->crtcId(),
event.globalX(),
event.globalY());
if (status) {
qWarning("failed to move cursor: %d", status);
}
}
void QKmsCursor::changeCursor(QCursor *windowCursor, QWindow *window)
{
Q_UNUSED(window)
if (!m_moved)
drmModeMoveCursor(m_screen->device()->fd(), m_screen->crtcId(), 0, 0);
const Qt::CursorShape newShape = windowCursor ? windowCursor->shape() : Qt::ArrowCursor;
if (newShape != Qt::BitmapCursor) {
m_cursorImage->set(newShape);
} else {
m_cursorImage->set(windowCursor->pixmap().toImage(),
windowCursor->hotSpot().x(),
windowCursor->hotSpot().y());
}
if (m_cursorImage->image()->width() > m_cursorSize.width() || m_cursorImage->image()->width() > m_cursorSize.height())
qWarning("cursor larger than %dx%d, cursor truncated", m_cursorSize.width(), m_cursorSize.height());
QImage cursorImage = m_cursorImage->image()->convertToFormat(QImage::Format_ARGB32)
.copy(0, 0, m_cursorSize.width(), m_cursorSize.height());
gbm_bo_write(m_cursorBufferObject, cursorImage.constBits(), cursorImage.byteCount());
quint32 handle = gbm_bo_get_handle(m_cursorBufferObject).u32;
int status = drmModeSetCursor(m_screen->device()->fd(),
m_screen->crtcId(), handle,
m_cursorSize.width(), m_cursorSize.height());
if (status) {
qWarning("failed to set cursor: %d", status);
}
}
QT_END_NAMESPACE

View File

@ -1,66 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QKMSCURSOR_H
#define QKMSCURSOR_H
#include <qpa/qplatformcursor.h>
struct gbm_device;
struct gbm_bo;
QT_BEGIN_NAMESPACE
class QKmsScreen;
class QKmsCursor : public QPlatformCursor
{
public:
QKmsCursor(QKmsScreen *screen);
~QKmsCursor();
void pointerEvent(const QMouseEvent &event) Q_DECL_OVERRIDE;
void changeCursor(QCursor *windowCursor, QWindow *window) Q_DECL_OVERRIDE;
private:
QKmsScreen *m_screen;
gbm_device *m_graphicsBufferManager;
gbm_bo *m_cursorBufferObject;
QPlatformCursorImage *m_cursorImage;
bool m_moved;
QSize m_cursorSize;
};
QT_END_NAMESPACE
#endif // QKMSCURSOR_H

View File

@ -1,118 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//#include <QDebug>
#include "qkmsscreen.h"
#include "qkmsdevice.h"
#include "qkmsintegration.h"
#include <QtCore/QSocketNotifier>
#include <QtCore/private/qcore_unix_p.h>
QT_BEGIN_NAMESPACE
QKmsDevice::QKmsDevice(const QString &path, QKmsIntegration *parent) :
QObject(0), m_integration(parent)
{
m_fd = QT_OPEN(path.toLatin1().constData(), O_RDWR);
if (m_fd < 0) {
qWarning("Could not open %s.", path.toLatin1().constData());
qFatal("No DRM display device");
}
m_graphicsBufferManager = gbm_create_device(m_fd);
m_eglDisplay = eglGetDisplay(m_graphicsBufferManager);
if (m_eglDisplay == EGL_NO_DISPLAY) {
qWarning("Could not open EGL display");
qFatal("EGL error");
}
EGLint major;
EGLint minor;
if (!eglInitialize(m_eglDisplay, &major, &minor)) {
qWarning("Could not initialize EGL display");
qFatal("EGL error");
}
createScreens();
// QSocketNotifier *notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
// connect(notifier, SIGNAL(activated(int)), this, SLOT(handlePageFlipCompleted()));
}
QKmsDevice::~QKmsDevice()
{
}
void QKmsDevice::createScreens()
{
drmModeRes *resources = drmModeGetResources(m_fd);
if (!resources)
qFatal("drmModeGetResources failed");
//Iterate connectors and create screens on each one active
for (int i = 0; i < resources->count_connectors; i++) {
drmModeConnector *connector = 0;
connector = drmModeGetConnector(m_fd, resources->connectors[i]);
if (connector && connector->connection == DRM_MODE_CONNECTED) {
m_integration->addScreen(new QKmsScreen(this, resources, connector));
}
drmModeFreeConnector(connector);
}
drmModeFreeResources(resources);
}
void QKmsDevice::handlePageFlipCompleted()
{
drmEventContext eventContext;
memset(&eventContext, 0, sizeof eventContext);
eventContext.version = DRM_EVENT_CONTEXT_VERSION;
eventContext.page_flip_handler = QKmsDevice::pageFlipHandler;
drmHandleEvent(m_fd, &eventContext);
}
void QKmsDevice::pageFlipHandler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data)
{
Q_UNUSED(fd)
Q_UNUSED(frame)
Q_UNUSED(sec)
Q_UNUSED(usec)
QKmsScreen *screen = static_cast<QKmsScreen *>(data);
screen->handlePageFlipped();
}
QT_END_NAMESPACE

View File

@ -1,81 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QKMSDEVICE_H
#define QKMSDEVICE_H
#include <stddef.h>
extern "C" {
#include <gbm.h>
}
#include <EGL/egl.h>
#include <QObject>
struct gbm_device;
QT_BEGIN_NAMESPACE
class QKmsIntegration;
class QKmsDevice : public QObject
{
Q_OBJECT
public:
explicit QKmsDevice(const QString &path, QKmsIntegration *parent);
~QKmsDevice();
EGLDisplay eglDisplay() { return m_eglDisplay; }
gbm_device *gbmDevice() { return m_graphicsBufferManager; }
int fd() const { return m_fd; }
static void pageFlipHandler(int fd, unsigned int frame, unsigned int sec,
unsigned int usec, void *data);
public slots:
void handlePageFlipCompleted();
private:
void createScreens();
QKmsIntegration *m_integration;
EGLDisplay m_eglDisplay;
EGLContext m_eglContext;
gbm_device *m_graphicsBufferManager;
int m_fd;
};
QT_END_NAMESPACE
#endif // QKMSDEVICE_H

View File

@ -1,204 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qkmsintegration.h"
#include "qkmsdevice.h"
#include "qkmsscreen.h"
#include "qkmswindow.h"
#include "qkmsbackingstore.h"
#include "qkmscontext.h"
#include "qkmsnativeinterface.h"
#if !defined(QT_NO_EVDEV)
#include <QtPlatformSupport/private/qevdevmousemanager_p.h>
#include <QtPlatformSupport/private/qevdevkeyboardmanager_p.h>
#include <QtPlatformSupport/private/qevdevtouch_p.h>
#endif
#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
#include <QtPlatformSupport/private/qgenericunixfontdatabase_p.h>
#include <QtPlatformSupport/private/qfbvthandler_p.h>
#include <QtPlatformSupport/private/qeglconvenience_p.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/QOpenGLContext>
#include <QtGui/QScreen>
#include <QtGui/QOffscreenSurface>
#include <qpa/qplatformoffscreensurface.h>
QT_BEGIN_NAMESPACE
QKmsIntegration::QKmsIntegration()
: QPlatformIntegration(),
m_fontDatabase(new QGenericUnixFontDatabase()),
m_nativeInterface(new QKmsNativeInterface),
m_vtHandler(0),
m_deviceDiscovery(0)
{
}
QKmsIntegration::~QKmsIntegration()
{
delete m_deviceDiscovery;
foreach (QKmsDevice *device, m_devices) {
delete device;
}
foreach (QPlatformScreen *screen, m_screens) {
destroyScreen(screen);
}
delete m_fontDatabase;
delete m_vtHandler;
}
void QKmsIntegration::initialize()
{
qputenv("EGL_PLATFORM", "drm");
m_vtHandler = new QFbVtHandler;
m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_DRM | QDeviceDiscovery::Device_DRM_PrimaryGPU, 0);
if (m_deviceDiscovery) {
QStringList devices = m_deviceDiscovery->scanConnectedDevices();
foreach (const QString &device, devices)
addDevice(device);
connect(m_deviceDiscovery, SIGNAL(deviceDetected(QString)), this, SLOT(addDevice(QString)));
connect(m_deviceDiscovery, SIGNAL(deviceRemoved(QString)), this, SLOT(removeDevice(QString)));
}
#if !defined(QT_NO_EVDEV)
new QEvdevKeyboardManager(QLatin1String("EvdevKeyboard"), QString() /* spec */, this);
new QEvdevMouseManager(QLatin1String("EvdevMouse"), QString() /* spec */, this);
new QEvdevTouchScreenHandlerThread(QString() /* spec */, this);
#endif
}
void QKmsIntegration::addDevice(const QString &deviceNode)
{
m_devices.append(new QKmsDevice(deviceNode, this));
}
void QKmsIntegration::removeDevice(const QString &deviceNode)
{
// TODO: support hot-plugging some day?
Q_UNUSED(deviceNode);
}
bool QKmsIntegration::hasCapability(QPlatformIntegration::Capability cap) const
{
switch (cap) {
case ThreadedPixmaps: return true;
case OpenGL: return true;
case ThreadedOpenGL: return false;
case RasterGLSurface: return true;
default: return QPlatformIntegration::hasCapability(cap);
}
}
QPlatformOpenGLContext *QKmsIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
{
QKmsScreen *screen = static_cast<QKmsScreen *>(context->screen()->handle());
return new QKmsContext(context, screen->device());
}
QPlatformWindow *QKmsIntegration::createPlatformWindow(QWindow *window) const
{
QKmsWindow *w = new QKmsWindow(window);
w->requestActivateWindow();
return w;
}
QPlatformBackingStore *QKmsIntegration::createPlatformBackingStore(QWindow *window) const
{
return new QKmsBackingStore(window);
}
// Neither a pbuffer nor a hidden QWindow is suitable. Just use an additional, small gbm surface.
QKmsOffscreenWindow::QKmsOffscreenWindow(EGLDisplay display, const QSurfaceFormat &format, QOffscreenSurface *offscreenSurface)
: QPlatformOffscreenSurface(offscreenSurface)
, m_format(format)
, m_display(display)
, m_surface(EGL_NO_SURFACE)
, m_window(0)
{
QKmsScreen *screen = static_cast<QKmsScreen *>(offscreenSurface->screen()->handle());
m_window = gbm_surface_create(screen->device()->gbmDevice(),
10, 10,
GBM_FORMAT_XRGB8888,
GBM_BO_USE_RENDERING);
if (!m_window) {
qWarning("QKmsOffscreenWindow: Failed to create native window");
return;
}
EGLConfig config = q_configFromGLFormat(m_display, m_format);
m_surface = eglCreateWindowSurface(m_display, config, m_window, 0);
if (m_surface != EGL_NO_SURFACE)
m_format = q_glFormatFromConfig(m_display, config);
}
QKmsOffscreenWindow::~QKmsOffscreenWindow()
{
if (m_surface != EGL_NO_SURFACE)
eglDestroySurface(m_display, m_surface);
if (m_window)
gbm_surface_destroy((gbm_surface *) m_window);
}
QPlatformOffscreenSurface *QKmsIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
{
QKmsScreen *screen = static_cast<QKmsScreen *>(surface->screen()->handle());
return new QKmsOffscreenWindow(screen->device()->eglDisplay(), QKmsScreen::tweakFormat(surface->format()), surface);
}
QPlatformFontDatabase *QKmsIntegration::fontDatabase() const
{
return m_fontDatabase;
}
void QKmsIntegration::addScreen(QKmsScreen *screen)
{
m_screens.append(screen);
screenAdded(screen);
}
QAbstractEventDispatcher *QKmsIntegration::createEventDispatcher() const
{
return createUnixEventDispatcher();
}
QPlatformNativeInterface *QKmsIntegration::nativeInterface() const
{
return m_nativeInterface;
}
QT_END_NAMESPACE

View File

@ -1,108 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QPLATFORMINTEGRATION_KMS_H
#define QPLATFORMINTEGRATION_KMS_H
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformnativeinterface.h>
#include <qpa/qplatformoffscreensurface.h>
#include <QtPlatformSupport/private/qdevicediscovery_p.h>
#include <EGL/egl.h>
QT_BEGIN_NAMESPACE
class QKmsScreen;
class QKmsDevice;
class QFbVtHandler;
class QKmsOffscreenWindow : public QPlatformOffscreenSurface
{
public:
QKmsOffscreenWindow(EGLDisplay display, const QSurfaceFormat &format, QOffscreenSurface *offscreenSurface);
~QKmsOffscreenWindow();
QSurfaceFormat format() const Q_DECL_OVERRIDE { return m_format; }
bool isValid() const Q_DECL_OVERRIDE { return m_surface != EGL_NO_SURFACE; }
EGLSurface surface() const { return m_surface; }
private:
QSurfaceFormat m_format;
EGLDisplay m_display;
EGLSurface m_surface;
EGLNativeWindowType m_window;
};
class QKmsIntegration : public QObject, public QPlatformIntegration
{
Q_OBJECT
public:
QKmsIntegration();
~QKmsIntegration();
void initialize() Q_DECL_OVERRIDE;
bool hasCapability(QPlatformIntegration::Capability cap) const Q_DECL_OVERRIDE;
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const Q_DECL_OVERRIDE;
QPlatformWindow *createPlatformWindow(QWindow *window) const Q_DECL_OVERRIDE;
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const Q_DECL_OVERRIDE;
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const Q_DECL_OVERRIDE;
QPlatformFontDatabase *fontDatabase() const Q_DECL_OVERRIDE;
QAbstractEventDispatcher *createEventDispatcher() const Q_DECL_OVERRIDE;
QPlatformNativeInterface *nativeInterface() const Q_DECL_OVERRIDE;
void addScreen(QKmsScreen *screen);
QObject *createDevice(const char *);
private slots:
void addDevice(const QString &deviceNode);
void removeDevice(const QString &deviceNode);
private:
QStringList findDrmDevices();
QList<QPlatformScreen *> m_screens;
QList<QKmsDevice *> m_devices;
QPlatformFontDatabase *m_fontDatabase;
QPlatformNativeInterface *m_nativeInterface;
QFbVtHandler *m_vtHandler;
QDeviceDiscovery *m_deviceDiscovery;
};
QT_END_NAMESPACE
#endif

View File

@ -1,135 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <private/qguiapplication_p.h>
#include "qkmsnativeinterface.h"
#include "qkmsdevice.h"
#include "qscreen.h"
#include "qkmscontext.h"
#include <QOpenGLContext>
class QKmsResourceMap : public QMap<QByteArray, QKmsNativeInterface::ResourceType>
{
public:
QKmsResourceMap()
:QMap<QByteArray, QKmsNativeInterface::ResourceType>()
{
insert("egldisplay", QKmsNativeInterface::EglDisplay);
insert("eglcontext", QKmsNativeInterface::EglContext);
}
};
Q_GLOBAL_STATIC(QKmsResourceMap, qKmsResourceMap)
void *QKmsNativeInterface::nativeResourceForIntegration(const QByteArray &resourceString)
{
QByteArray lowerCaseResource = resourceString.toLower();
ResourceType resource = qKmsResourceMap()->value(lowerCaseResource);
void *result = 0;
switch (resource) {
case EglDisplay:
result = eglDisplay();
break;
default:
result = 0;
}
return result;
}
void *QKmsNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window)
{
QByteArray lowerCaseResource = resourceString.toLower();
ResourceType resource = qKmsResourceMap()->value(lowerCaseResource);
void *result = 0;
switch (resource) {
case EglDisplay:
result = eglDisplayForWindow(window);
break;
case EglContext:
result = eglContextForWindow(window);
break;
default:
result = 0;
}
return result;
}
QPlatformNativeInterface::NativeResourceForContextFunction QKmsNativeInterface::nativeResourceFunctionForContext(const QByteArray &resource)
{
QByteArray lowerCaseResource = resource.toLower();
if (lowerCaseResource == "get_egl_context") {
return eglContextForContext;
}
return 0;
}
void *QKmsNativeInterface::eglDisplay()
{
//QKmsIntegration *integration = static_cast<QKmsIntegration *>(QGuiApplicationPrivate::platformIntegration());
QKmsScreen *screen = static_cast<QKmsScreen *>(QGuiApplication::primaryScreen()->handle());
if (!screen || !screen->device())
return 0;
return screen->device()->eglDisplay();
}
void *QKmsNativeInterface::eglDisplayForWindow(QWindow *window)
{
QKmsScreen *screen = qPlatformScreenForWindow(window);
if (!screen)
return 0;
QKmsDevice *device = screen->device();
if (!device)
return 0;
return device->eglDisplay();
}
void *QKmsNativeInterface::eglContextForWindow(QWindow *)
{
return 0;
}
QKmsScreen *QKmsNativeInterface::qPlatformScreenForWindow(QWindow *window)
{
QScreen *screen = window ? window->screen() : QGuiApplication::primaryScreen();
return static_cast<QKmsScreen *>(screen->handle());
}
void *QKmsNativeInterface::eglContextForContext(QOpenGLContext *context)
{
Q_ASSERT(context);
QKmsContext *eglPlatformContext = static_cast<QKmsContext *>(context->handle());
return eglPlatformContext->eglContext();
}

View File

@ -1,64 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QKMSNATIVEINTERFACE_H
#define QKMSNATIVEINTERFACE_H
#include "qkmsscreen.h"
#include <qpa/qplatformnativeinterface.h>
class QKmsNativeInterface : public QPlatformNativeInterface
{
public:
enum ResourceType {
EglDisplay,
EglContext
};
void *nativeResourceForIntegration(const QByteArray &resource) Q_DECL_OVERRIDE;
void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) Q_DECL_OVERRIDE;
NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource) Q_DECL_OVERRIDE;
void *eglDisplay();
void *eglDisplayForWindow(QWindow *window);
void *eglContextForWindow(QWindow *window);
static void *eglContextForContext(QOpenGLContext *context);
private:
static QKmsScreen *qPlatformScreenForWindow(QWindow *window);
};
#endif // QKMSNATIVEINTERFACE_H

View File

@ -1,275 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qkmsscreen.h"
#include "qkmscursor.h"
#include "qkmsdevice.h"
#include "qkmscontext.h"
#include <QtPlatformSupport/private/qeglconvenience_p.h>
#include <QCoreApplication>
#include <QtDebug>
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcQpaScreen, "qt.qpa.kms.screen")
//Fallback mode (taken from Wayland DRM demo compositor)
static drmModeModeInfo builtin_1024x768 = {
63500, //clock
1024, 1072, 1176, 1328, 0,
768, 771, 775, 798, 0,
59920,
DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC,
0,
"1024x768"
};
QKmsScreen::QKmsScreen(QKmsDevice *device, const drmModeRes *resources, const drmModeConnector *connector)
: m_device(device),
m_current_bo(0),
m_next_bo(0),
m_connectorId(connector->connector_id),
m_depth(32),
m_format(QImage::Format_Invalid),
m_eglWindowSurface(EGL_NO_SURFACE),
m_modeSet(false)
{
m_cursor = new QKmsCursor(this);
initializeScreenMode(resources, connector);
}
QKmsScreen::~QKmsScreen()
{
delete m_cursor;
drmModeSetCrtc(m_device->fd(), m_oldCrtc->crtc_id, m_oldCrtc->buffer_id,
m_oldCrtc->x, m_oldCrtc->y,
&m_connectorId, 1, &m_oldCrtc->mode);
drmModeFreeCrtc(m_oldCrtc);
if (m_eglWindowSurface != EGL_NO_SURFACE)
eglDestroySurface(m_device->eglDisplay(), m_eglWindowSurface);
gbm_surface_destroy(m_gbmSurface);
}
QRect QKmsScreen::geometry() const
{
return m_geometry;
}
int QKmsScreen::depth() const
{
return m_depth;
}
QImage::Format QKmsScreen::format() const
{
return m_format;
}
QSizeF QKmsScreen::physicalSize() const
{
return m_physicalSize;
}
QPlatformCursor *QKmsScreen::cursor() const
{
return m_cursor;
}
void QKmsScreen::initializeScreenMode(const drmModeRes *resources, const drmModeConnector *connector)
{
//Determine optimal mode for screen
drmModeModeInfo *mode = 0;
for (int i = 0; i < connector->count_modes; ++i) {
if (connector->modes[i].type & DRM_MODE_TYPE_PREFERRED) {
mode = &connector->modes[i];
break;
}
}
if (!mode) {
if (connector->count_modes > 0)
mode = &connector->modes[0];
else
mode = &builtin_1024x768;
}
drmModeEncoder *encoder = drmModeGetEncoder(m_device->fd(), connector->encoders[0]);
if (encoder == 0)
qFatal("No encoder for connector.");
int i;
for (i = 0; i < resources->count_crtcs; i++) {
if (encoder->possible_crtcs & (1 << i))
break;
}
if (i == resources->count_crtcs)
qFatal("No usable crtc for encoder.");
m_oldCrtc = drmModeGetCrtc(m_device->fd(), encoder->crtc_id);
m_crtcId = resources->crtcs[i];
m_mode = *mode;
m_geometry = QRect(0, 0, m_mode.hdisplay, m_mode.vdisplay);
qCDebug(lcQpaScreen) << "kms initialized with geometry" << m_geometry;
m_depth = 32;
m_format = QImage::Format_RGB32;
m_physicalSize = QSizeF(connector->mmWidth, connector->mmHeight);
m_gbmSurface = gbm_surface_create(m_device->gbmDevice(),
m_mode.hdisplay, m_mode.vdisplay,
GBM_BO_FORMAT_XRGB8888,
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
qCDebug(lcQpaScreen) << "created gbm surface" << m_gbmSurface << m_mode.hdisplay << m_mode.vdisplay;
//Cleanup
drmModeFreeEncoder(encoder);
}
QSurfaceFormat QKmsScreen::tweakFormat(const QSurfaceFormat &format)
{
QSurfaceFormat fmt = format;
fmt.setRedBufferSize(8);
fmt.setGreenBufferSize(8);
fmt.setBlueBufferSize(8);
if (fmt.alphaBufferSize() != -1)
fmt.setAlphaBufferSize(8);
return fmt;
}
void QKmsScreen::initializeWithFormat(const QSurfaceFormat &format)
{
EGLDisplay display = m_device->eglDisplay();
EGLConfig config = q_configFromGLFormat(display, tweakFormat(format));
m_eglWindowSurface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)m_gbmSurface, NULL);
qCDebug(lcQpaScreen) << "created window surface";
m_surfaceFormat = q_glFormatFromConfig(display, config);
}
void QKmsScreen::swapBuffers()
{
eglSwapBuffers(m_device->eglDisplay(), m_eglWindowSurface);
m_next_bo = gbm_surface_lock_front_buffer(m_gbmSurface);
if (!m_next_bo)
qFatal("kms: Failed to lock front buffer");
performPageFlip();
}
void QKmsScreen::performPageFlip()
{
if (!m_next_bo)
return;
uint32_t width = gbm_bo_get_width(m_next_bo);
uint32_t height = gbm_bo_get_height(m_next_bo);
uint32_t stride = gbm_bo_get_stride(m_next_bo);
uint32_t handle = gbm_bo_get_handle(m_next_bo).u32;
uint32_t fb_id;
int ret = drmModeAddFB(m_device->fd(), width, height, 24, 32,
stride, handle, &fb_id);
if (ret) {
qFatal("kms: Failed to create fb: fd %d, w %d, h %d, stride %d, handle %d, ret %d",
m_device->fd(), width, height, stride, handle, ret);
}
if (!m_modeSet) {
//Set the Mode of the screen.
int ret = drmModeSetCrtc(m_device->fd(), m_crtcId, fb_id,
0, 0, &m_connectorId, 1, &m_mode);
if (ret)
qFatal("failed to set mode");
m_modeSet = true;
// Initialize cursor
static int hideCursor = qEnvironmentVariableIntValue("QT_QPA_KMS_HIDECURSOR");
if (!hideCursor) {
QCursor cursor(Qt::ArrowCursor);
m_cursor->changeCursor(&cursor, 0);
}
}
int pageFlipStatus = drmModePageFlip(m_device->fd(), m_crtcId,
fb_id,
DRM_MODE_PAGE_FLIP_EVENT, this);
if (pageFlipStatus)
{
qWarning("Pageflip status: %d", pageFlipStatus);
gbm_surface_release_buffer(m_gbmSurface, m_next_bo);
m_next_bo = 0;
}
}
void QKmsScreen::handlePageFlipped()
{
if (m_current_bo)
gbm_surface_release_buffer(m_gbmSurface, m_current_bo);
m_current_bo = m_next_bo;
m_next_bo = 0;
}
QKmsDevice * QKmsScreen::device() const
{
return m_device;
}
void QKmsScreen::waitForPageFlipComplete()
{
while (m_next_bo) {
#if 0
//Check manually if there is something to be read on the device
//as there are senarios where the signal is not received (starvation)
fd_set fdSet;
timeval timeValue;
int returnValue;
FD_ZERO(&fdSet);
FD_SET(m_device->fd(), &fdSet);
timeValue.tv_sec = 0;
timeValue.tv_usec = 1000;
returnValue = select(1, &fdSet, 0, 0, &timeValue);
printf("select returns %d\n", returnValue);
#endif
m_device->handlePageFlipCompleted();
}
}
QT_END_NAMESPACE

View File

@ -1,122 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QKMSSCREEN_H
#define QKMSSCREEN_H
#include <stddef.h>
#define EGL_EGLEXT_PROTOTYPES 1
#define GL_GLEXT_PROTOTYPES 1
extern "C" {
#include <gbm.h>
#include <xf86drmMode.h>
#include <xf86drm.h>
}
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <QtGui/qopengl.h>
#include <QtGui/qsurfaceformat.h>
#include <QtCore/qloggingcategory.h>
#include <qpa/qplatformscreen.h>
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(lcQpaScreen)
class QKmsCursor;
class QKmsDevice;
class QKmsContext;
class QKmsScreen : public QPlatformScreen
{
public:
QKmsScreen(QKmsDevice *device, const drmModeRes *resources, const drmModeConnector *connector);
~QKmsScreen();
QRect geometry() const Q_DECL_OVERRIDE;
int depth() const Q_DECL_OVERRIDE;
QImage::Format format() const Q_DECL_OVERRIDE;
QSizeF physicalSize() const Q_DECL_OVERRIDE;
QPlatformCursor *cursor() const Q_DECL_OVERRIDE;
quint32 crtcId() const { return m_crtcId; }
QKmsDevice *device() const;
void initializeWithFormat(const QSurfaceFormat &format);
//Called by context for each screen
void swapBuffers();
void handlePageFlipped();
EGLSurface eglSurface() const { return m_eglWindowSurface; }
void waitForPageFlipComplete();
static QSurfaceFormat tweakFormat(const QSurfaceFormat &format);
QSurfaceFormat surfaceFormat() const { return m_surfaceFormat; }
private:
void performPageFlip();
void initializeScreenMode(const drmModeRes *resources, const drmModeConnector *connector);
QKmsDevice *m_device;
gbm_bo *m_current_bo;
gbm_bo *m_next_bo;
quint32 m_connectorId;
quint32 m_crtcId;
drmModeModeInfo m_mode;
QRect m_geometry;
QSizeF m_physicalSize;
int m_depth;
QImage::Format m_format;
drmModeCrtcPtr m_oldCrtc;
QKmsCursor *m_cursor;
gbm_surface *m_gbmSurface;
EGLSurface m_eglWindowSurface;
bool m_modeSet;
QSurfaceFormat m_surfaceFormat;
};
QT_END_NAMESPACE
#endif // QKMSSCREEN_H

View File

@ -1,66 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qkmswindow.h"
#include "qkmsscreen.h"
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qplatformwindow_p.h>
QT_BEGIN_NAMESPACE
QKmsWindow::QKmsWindow(QWindow *window)
: QPlatformWindow(window)
{
Q_D(QPlatformWindow);
m_screen = QPlatformScreen::platformScreenForWindow(window);
static_cast<QKmsScreen *>(m_screen)->initializeWithFormat(window->requestedFormat());
setGeometry(d->rect); // rect is set to window->geometry() in base ctor
}
void QKmsWindow::setGeometry(const QRect &rect)
{
// All windows must be fullscreen
QRect fullscreenRect = m_screen->availableGeometry();
if (rect != fullscreenRect)
QWindowSystemInterface::handleGeometryChange(window(), fullscreenRect);
QPlatformWindow::setGeometry(fullscreenRect);
}
QSurfaceFormat QKmsWindow::format() const
{
return static_cast<QKmsScreen *>(m_screen)->surfaceFormat();
}
QT_END_NAMESPACE

View File

@ -1,57 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QKMSWINDOW_H
#define QKMSWINDOW_H
#include <qpa/qplatformwindow.h>
QT_BEGIN_NAMESPACE
class QKmsWindow : public QPlatformWindow
{
Q_DECLARE_PRIVATE(QPlatformWindow)
public:
QKmsWindow(QWindow *window);
void setGeometry(const QRect &rect) Q_DECL_OVERRIDE;
QSurfaceFormat format() const Q_DECL_OVERRIDE;
private:
QPlatformScreen *m_screen;
};
QT_END_NAMESPACE
#endif // QKMSWINDOW_H