diff options
author | Jørgen Lind <jorgen.lind@nokia.com> | 2010-04-23 06:38:44 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2010-04-28 15:12:33 (GMT) |
commit | 255371252bdad3cd370ccf95337c94baae7277a5 (patch) | |
tree | d384d822d5343c5e2463d5315b9ae2e3599525b7 | |
parent | 1acf354a1380586a754d2a0ed546e4dceb4296cb (diff) | |
download | Qt-255371252bdad3cd370ccf95337c94baae7277a5.zip Qt-255371252bdad3cd370ccf95337c94baae7277a5.tar.gz Qt-255371252bdad3cd370ccf95337c94baae7277a5.tar.bz2 |
Porting openkode platform plugin to new api
13 files changed, 294 insertions, 296 deletions
diff --git a/src/plugins/platforms/openkode/frag.h b/src/plugins/platforms/openkode/frag.h deleted file mode 100644 index 6575cb5..0000000 --- a/src/plugins/platforms/openkode/frag.h +++ /dev/null @@ -1,37 +0,0 @@ -0x4e,0x56,0x75,0x63,0x01,0x00,0x00,0x00,0x09,0x00,0x06,0x00,0x06,0x00,0x50,0x00, -0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x50,0x02,0x00,0x00,0x00,0x00,0x00,0x00, -0x03,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x40,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x27,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x50,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0xe8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x0b,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x90,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x11,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xb0,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x12,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0xc0,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x2b,0x00,0x00,0x00,0x7a,0x00,0x00,0x00,0xd0,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x2c,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x03,0x68,0x69,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff, -0x00,0x00,0x00,0x80,0x04,0x00,0x00,0x90,0x00,0x02,0x01,0x82,0x04,0x02,0x02,0x82, -0x01,0x00,0x40,0xf6,0x85,0xc7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x30,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x02,0x00,0x00,0x00,0x00,0x00,0x00, -0x3a,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x2a,0x00,0x06,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, -0x3b,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x02,0x00,0x00,0x00,0x00,0x00,0x00, -0x49,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x26,0x00,0x04,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, -0x00,0x74,0x65,0x78,0x5f,0x73,0x61,0x6d,0x70,0x00,0x00,0x00,0x74,0x65,0x78,0x63, -0x6f,0x6f,0x72,0x64,0x5f,0x76,0x61,0x72,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 diff --git a/src/plugins/platforms/openkode/main.cpp b/src/plugins/platforms/openkode/main.cpp index e9c1083..bd2b5c7 100644 --- a/src/plugins/platforms/openkode/main.cpp +++ b/src/plugins/platforms/openkode/main.cpp @@ -39,33 +39,33 @@ ** ****************************************************************************/ -#include <private/qgraphicssystemplugin_p.h> -#include "qgraphicssystem_openkode.h" +#include <QtGui/QPlatformIntegrationPlugin> +#include "qopenkodeintegration.h" QT_BEGIN_NAMESPACE -class QOpenKODEGraphicsSystemPlugin : public QGraphicsSystemPlugin +class QOpenKODEPlugin : public QPlatformIntegrationPlugin { public: QStringList keys() const; - QGraphicsSystem *create(const QString&); + QPlatformIntegration *create(const QString&); }; -QStringList QOpenKODEGraphicsSystemPlugin::keys() const +QStringList QOpenKODEPlugin::keys() const { QStringList list; list << "OpenKODE"; return list; } -QGraphicsSystem* QOpenKODEGraphicsSystemPlugin::create(const QString& system) +QPlatformIntegration * QOpenKODEPlugin::create(const QString& system) { if (system.toLower() == "openkode") - return new QOpenKODEGraphicsSystem; + return new QOpenKODEIntegration; return 0; } -Q_EXPORT_PLUGIN2(openkode, QOpenKODEGraphicsSystemPlugin) +Q_EXPORT_PLUGIN2(openkode, QOpenKODEPlugin) QT_END_NAMESPACE diff --git a/src/plugins/platforms/openkode/openkode.pro b/src/plugins/platforms/openkode/openkode.pro index 055048d..042b74d 100644 --- a/src/plugins/platforms/openkode/openkode.pro +++ b/src/plugins/platforms/openkode/openkode.pro @@ -1,14 +1,20 @@ -TARGET = qopenkodegraphicssystem +TARGET = qopenkodeintegration include(../../qpluginbase.pri) -QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/graphicssystems +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms -SOURCES = main.cpp qgraphicssystem_openkode.cpp qwindowsurface_openkode.cpp -HEADERS = qgraphicssystem_openkode.h qwindowsurface_openkode.h +SOURCES = main.cpp \ + qopenkodeintegration.cpp \ + qopenkodewindowsurface.cpp \ + qopenkodewindow.cpp -target.path += $$[QT_INSTALL_PLUGINS]/graphicssystems +HEADERS = qopenkodeintegration.h \ + qopenkodewindowsurface.h \ + qopenkodewindow.h + +RESOURCES = resources.qrc + +target.path += $$[QT_INSTALL_PLUGINS]/platforms INSTALLS += target -# openkode specific stuff -INCLUDEPATH += $(OPENKODE_DIR)/include -LIBS += $${QMAKE_RPATH}/$(OPENKODE_DIR)/lib-target -L$(OPENKODE_DIR)/lib-target -lKD -lEGL -lGLESv2 +LIBS += -lKD -lEGL -lGLESv2 diff --git a/src/plugins/platforms/openkode/qgraphicssystem_openkode.cpp b/src/plugins/platforms/openkode/qopenkodeintegration.cpp index 7a07776..d9430c2 100644 --- a/src/plugins/platforms/openkode/qgraphicssystem_openkode.cpp +++ b/src/plugins/platforms/openkode/qopenkodeintegration.cpp @@ -39,12 +39,15 @@ ** ****************************************************************************/ -#include "qgraphicssystem_openkode.h" -#include "qwindowsurface_openkode.h" +#include "qopenkodeintegration.h" +#include "qopenkodewindowsurface.h" +#include "qopenkodewindow.h" + #include <QtGui/private/qpixmap_raster_p.h> #include <QtCore/qdebug.h> #include <QtCore/qthread.h> +#include <QtCore/qfile.h> #include <KD/kd.h> #include <KD/NV_display.h> @@ -52,15 +55,17 @@ #include "GLES2/gl2ext.h" +#include <nvgl2demo_common.h> + QT_BEGIN_NAMESPACE -QOpenKODEGraphicsSystemScreen::QOpenKODEGraphicsSystemScreen() +QOpenKODEScreen::QOpenKODEScreen() { KDDesktopNV *kdDesktop = KD_NULL; KDDisplayNV *kdDisplay = KD_NULL; - qDebug() << "QOpenKODEGraphicsSystemScreen::QOpenKODEGraphicsSystemScreen()"; + qDebug() << "QOpenKODEScreen::QOpenKODEIntegrationScreen()"; // Get the default desktop and display kdDesktop = kdGetDesktopNV(KD_DEFAULT_DESKTOP_NV, KD_NULL); @@ -100,48 +105,40 @@ QOpenKODEGraphicsSystemScreen::QOpenKODEGraphicsSystemScreen() mPhysicalSize = QSize(mode.width * 25.4 / defaultDpi, mode.height * 25.4 / defaultDpi); mDepth = 24; - mFormat = QImage::Format_RGB888; - - - QEglProperties properties; - properties.setPixelFormat(QImage::Format_RGB888); - properties.setValue(EGL_BUFFER_SIZE, EGL_DONT_CARE); - properties.setRenderableType(QEgl::OpenGL); - - if (!mContext.chooseConfig(properties, QEgl::BestPixelFormat)) { - qWarning("qEglContext: Unable to choose config!"); - return; - } - - if (!mContext.display()) { - qWarning("qEglContext: Unable to open display!"); - return; - } - - qDebug() << " - QEglContext::openDisplay OK"; + mFormat = QImage::Format_RGB32; } -static GLuint NvKdTestLoadShaders(const char *vertex_shader_binary, - const char *fragment_shader_binary, - GLuint vertex_shader_binary_size, - GLuint fragment_shader_binary_size) +static GLuint loadShaders(const QString &vertexShader, const QString &fragmentShader) { - GLuint prog; + GLuint prog = 0; GLuint vertShader; GLuint fragShader; - // Create the program + // Create the program prog = glCreateProgram(); // Create the GL shader objects vertShader = glCreateShader(GL_VERTEX_SHADER); fragShader = glCreateShader(GL_FRAGMENT_SHADER); - // Load the binary data into the shader objects - glShaderBinary(1, &vertShader, - GL_NVIDIA_PLATFORM_BINARY_NV, vertex_shader_binary, vertex_shader_binary_size); - glShaderBinary(1, &fragShader, - GL_NVIDIA_PLATFORM_BINARY_NV, fragment_shader_binary, fragment_shader_binary_size); + // Load shader sources into GL and compile + QFile vertexFile(vertexShader); + vertexFile.open(QFile::ReadOnly); + QByteArray vertSource = vertexFile.readAll(); + const char *vertChar = vertSource.constData(); + int vertSize = vertSource.size(); + + QFile fragFile(fragmentShader); + fragFile.open(QFile::ReadOnly); + QByteArray fragSource = fragFile.readAll(); + const char *fragChar = fragSource.constData(); + int fragSize = fragSource.size(); + + glShaderSource(vertShader, 1, (const char**)&vertChar, &vertSize); + glCompileShader(vertShader); + + glShaderSource(fragShader, 1, (const char**)&fragChar, &fragSize); + glCompileShader(fragShader); // Attach the shaders to the program glAttachShader(prog, vertShader); @@ -170,9 +167,9 @@ public: protected: void run() { - qDebug() << "initializing KD"; - kdInitializeNV(); - qDebug() << "done initializing KD"; + if (kdInitializeNV() == KD_ENOTINITIALIZED) { + qFatal("Did not manage to initialize openkode"); + } eventMutex->release(); const KDEvent *event; @@ -180,52 +177,46 @@ protected: qDebug() << "!!! received event!"; kdDefaultEvent(event); } - - qDebug() << "exiting event loop"; } private: QSemaphore *eventMutex; }; -QOpenKODEGraphicsSystem::QOpenKODEGraphicsSystem() +QOpenKODEIntegration::QOpenKODEIntegration() : eventMutex(1) { QOpenKODEEventLoopHelper *loop = new QOpenKODEEventLoopHelper(&eventMutex); loop->start(); eventMutex.acquire(); // block until initialization done - mPrimaryScreen = new QOpenKODEGraphicsSystemScreen(); + QOpenKODEScreen *mPrimaryScreen = new QOpenKODEScreen(); mScreens.append(mPrimaryScreen); } -QPixmapData *QOpenKODEGraphicsSystem::createPixmapData(QPixmapData::PixelType type) const +QPixmapData *QOpenKODEIntegration::createPixmapData(QPixmapData::PixelType type) const { return new QRasterPixmapData(type); } -QWindowSurface *QOpenKODEGraphicsSystem::createWindowSurface(QWidget *widget) const +QPlatformWindow *QOpenKODEIntegration::createPlatformWindow(QWidget *tlw, WId ) const { - return new QOpenKODEWindowSurface(mPrimaryScreen, widget); + return new QOpenKODEWindow(tlw); } -GLuint QOpenKODEGraphicsSystem::blitterProgram() +QWindowSurface *QOpenKODEIntegration::createWindowSurface(QWidget *widget, WId winId) const +{ + return new QOpenKODEWindowSurface(widget,winId); +} + +GLuint QOpenKODEIntegration::blitterProgram() { static GLuint shaderProgram = 0; if (!shaderProgram) { - const char vertShaderBinary[] = { -# include "vert.h" - }; - const char fragShaderBinary[] = { -# include "frag.h" - }; - - shaderProgram = NvKdTestLoadShaders(vertShaderBinary, fragShaderBinary, - sizeof(vertShaderBinary), sizeof(fragShaderBinary)); - + shaderProgram = loadShaders(":/shaders/vert.glslv",":/shaders/frag.glslf"); if (!shaderProgram) qFatal("QOpenKodeGraphicsSystem(): Cannot load shaders!"); } diff --git a/src/plugins/platforms/openkode/qgraphicssystem_openkode.h b/src/plugins/platforms/openkode/qopenkodeintegration.h index 7d73ae0..76ce219 100644 --- a/src/plugins/platforms/openkode/qgraphicssystem_openkode.h +++ b/src/plugins/platforms/openkode/qopenkodeintegration.h @@ -44,7 +44,8 @@ #include <QtCore/qsemaphore.h> -#include <QtGui/private/qgraphicssystem_p.h> +#include <QtGui/QPlatformIntegration> +#include <QtGui/QPlatformScreen> #include <QtGui/private/qeglcontext_p.h> # include <GLES2/gl2.h> @@ -53,11 +54,11 @@ QT_BEGIN_NAMESPACE struct KDDesktopNV; -class QOpenKODEGraphicsSystemScreen : public QGraphicsSystemScreen +class QOpenKODEScreen : public QPlatformScreen { public: - QOpenKODEGraphicsSystemScreen(); - ~QOpenKODEGraphicsSystemScreen() {} + QOpenKODEScreen(); + ~QOpenKODEScreen() {} QRect geometry() const { return mGeometry; } int depth() const { return mDepth; } @@ -69,24 +70,23 @@ public: int mDepth; QImage::Format mFormat; QSize mPhysicalSize; - QEglContext mContext; }; -class QOpenKODEGraphicsSystem : public QGraphicsSystem +class QOpenKODEIntegration : public QPlatformIntegration { public: - QOpenKODEGraphicsSystem(); + QOpenKODEIntegration(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QWindowSurface *createWindowSurface(QWidget *widget) const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const; + QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; - QList<QGraphicsSystemScreen *> screens() const { return mScreens; } + virtual QList<QPlatformScreen *> screens() const { return mScreens; } static GLuint blitterProgram(); private: - QOpenKODEGraphicsSystemScreen *mPrimaryScreen; - QList<QGraphicsSystemScreen *> mScreens; + QList<QPlatformScreen *> mScreens; QSemaphore eventMutex; }; diff --git a/src/plugins/platforms/openkode/qopenkodewindow.cpp b/src/plugins/platforms/openkode/qopenkodewindow.cpp new file mode 100644 index 0000000..8e1527c --- /dev/null +++ b/src/plugins/platforms/openkode/qopenkodewindow.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenVG module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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 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.0, 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qopenkodewindow.h" + +#include <KD/NV_display.h> + +#include <QtGui/private/qeglcontext_p.h> +#include <QtGui/qwidget.h> +#include <QtCore/QDebug> + +QOpenKODEWindow::QOpenKODEWindow(QWidget *tlw) + : QPlatformWindow(tlw) +{ + /* Initialize EGL display */ + EGLBoolean rvbool = eglInitialize(QEgl::display(), KD_NULL, KD_NULL); + if (!rvbool) { + kdLogMessage("EGL failed to initialize display\n"); + } + + kdWindow = kdCreateWindow(QEgl::display(), + QEgl::defaultConfig(QInternal::Widget,QEgl::OpenGL,QEgl::Renderable), + KD_NULL); + if (!kdWindow) { + qErrnoWarning(kdGetError(), "Error creating native window"); + return; + } + + const KDint windowSize[2] = { tlw->width(), tlw->height() }; + if (kdSetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { + qErrnoWarning(kdGetError(), "Could not set native window size"); + return; + } + +// const KDboolean windowExclusive[] = { false }; +// if (kdSetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_DESKTOP_EXCLUSIVE_NV, windowExclusive)) { +// qErrnoWarning(kdGetError(), "Could not set exclusive bit"); +// //return; +// } +// +// const KDint windowPos[2] = { tlw->x(), tlw->y() }; +// if (kdSetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { +// qErrnoWarning(kdGetError(), "Could not set native window position"); +// return; +// } + + if (kdRealizeWindow(kdWindow, &eglWindow)) { + qErrnoWarning(kdGetError(), "Could not realize native window"); + return; + } +} + +void QOpenKODEWindow::setGeometry(const QRect &rect) +{ + const QRect geo = geometry(); + if (geo.size() != rect.size()) { + const KDint windowSize[2] = { rect.width(), rect.height() }; + if (kdSetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { + qErrnoWarning(kdGetError(), "Could not set native window size"); + //return; + } + } + +// if (geo.topLeft() != rect.topLeft()) { +// const KDint windowPos[2] = { rect.x(), rect.y() }; +// if (kdSetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { +// qErrnoWarning(kdGetError(), "Could not set native window position"); +// //return; +// } +// } + +} + +void QOpenKODEWindow::setVisible(bool visible) +{ + +} diff --git a/src/plugins/platforms/openkode/qopenkodewindow.h b/src/plugins/platforms/openkode/qopenkodewindow.h new file mode 100644 index 0000000..b52f8e6 --- /dev/null +++ b/src/plugins/platforms/openkode/qopenkodewindow.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenVG module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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 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.0, 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENKODEWINDOW_H +#define QOPENKODEWINDOW_H + +#include <QtGui/QPlatformWindow> + +#include <KD/kd.h> + +class QOpenKODEWindow : public QPlatformWindow +{ +public: + QOpenKODEWindow(QWidget *tlw); + + void setGeometry(const QRect &rect); + void setVisible(bool visible); + WId winId() const { return WId(eglWindow); } + +private: + struct KDWindow *kdWindow; + EGLNativeWindowType eglWindow; +}; + +#endif //QOPENKODEWINDOW_H diff --git a/src/plugins/platforms/openkode/qwindowsurface_openkode.cpp b/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp index b3f3965..5eb0d2d 100644 --- a/src/plugins/platforms/openkode/qwindowsurface_openkode.cpp +++ b/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp @@ -39,99 +39,27 @@ ** ****************************************************************************/ -#include "qwindowsurface_openkode.h" -#include "qgraphicssystem_openkode.h" -#include <QtCore/qdebug.h> +#include "qopenkodewindowsurface.h" +#include "qopenkodeintegration.h" + +#include "qopenkodewindow.h" -#include "KD/kd.h" -#include "KD/NV_display.h" +#include <QtCore/qdebug.h> QT_BEGIN_NAMESPACE QOpenKODEWindowSurface::QOpenKODEWindowSurface - (QOpenKODEGraphicsSystemScreen *screen, QWidget *window) + (QWidget *window, WId winId) : QWindowSurface(window), - mScreen(screen), - mSurface(0) + mSurface(EGL_NO_SURFACE), + mWin((EGLNativeWindowType) winId) { - qDebug() << "QOpenKODEWindowSurface::QOpenKODEWindowSurface:" << window << window->width() << "x" << window->height() - << "pos" << window->x() << "x" << window->y(); - - if (!mContext.display()) { - qWarning("qEglContext: Unable to open display!"); - return; - } - - QEglProperties properties; - properties.setPixelFormat(QImage::Format_RGB888); - properties.setValue(EGL_BUFFER_SIZE, EGL_DONT_CARE); - properties.setRenderableType(QEgl::OpenGL); - - if (!mContext.chooseConfig(properties, QEgl::BestPixelFormat)) { - qWarning("qEglContext: Unable to choose config!"); - return; - } - - createWindow(window); -} - -void QOpenKODEWindowSurface::createWindow(QWidget *window) -{ - qDebug() << "createWindow"; - kdWindow = kdCreateWindow(mContext.display(), mContext.config(), KD_NULL); - - if (!kdWindow) { - qErrnoWarning(kdGetError(), "Error creating native window"); - return; - } - - const KDint windowSize[2] = { window->width(), window->height() }; - if (kdSetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { - qErrnoWarning(kdGetError(), "Could not set native window size"); - return; - } - - //const KDboolean windowExclusive[] = { false }; - //if (kdSetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_DESKTOP_EXCLUSIVE_NV, windowExclusive)) { - // qErrnoWarning(kdGetError(), "Could not set exclusive bit"); - // //return; - //} - - //const KDint windowPos[2] = { window->x(), window->y() }; - //if (kdSetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { - // qErrnoWarning(kdGetError(), "Could not set native window position"); - // //return; - //} - - EGLNativeWindowType nativeWindow; - - if (kdRealizeWindow(kdWindow, &nativeWindow)) { - qErrnoWarning(kdGetError(), "Could not realize native window"); - return; - } - qDebug() << "kdRealizeWindow" << nativeWindow; - - // Create an EGL window surface for the native window - EGLint windowAttrs[3] = { EGL_NONE }; - qDebug() << "doing createwindowsurface"; - *mSurface = eglCreateWindowSurface(mContext.display(), - mContext.config(), - nativeWindow, - windowAttrs); - qDebug() << "create windowsurface"; - if (!mSurface) { - qWarning("EGL couldn't create window surface: 0x%x", eglGetError()); - return; - } - - qDebug() << "making context"; + EGLConfig config = QEgl::defaultConfig(QInternal::Widget,QEgl::OpenGL,QEgl::Renderable); + mContext.setConfig(config); if (!mContext.createContext()) { - qDebug() << "Unable to create context!"; + qWarning("QOpenKODEWindowSurface: Unable to create context"); return; } - - qDebug() << "about to make current"; - mContext.makeCurrent(mSurface); } QOpenKODEWindowSurface::~QOpenKODEWindowSurface() @@ -140,14 +68,14 @@ QOpenKODEWindowSurface::~QOpenKODEWindowSurface() QPaintDevice *QOpenKODEWindowSurface::paintDevice() { - qDebug() << "QOpenKODEWindowSurface::paintDevice"; return &mImage; } // ### TODO - this updates the entire toplevel, should only update the region void QOpenKODEWindowSurface::flush(QWidget *, const QRegion ®ion, const QPoint &offset) { - qDebug() << "in flush"; + mContext.makeCurrent(mSurface); + if (!offset.isNull()) { qWarning("Offset flushing not supported yet"); return; @@ -177,7 +105,7 @@ void QOpenKODEWindowSurface::flush(QWidget *, const QRegion ®ion, const QPoin // qDebug() << "flush" << widget << offset << region.boundingRect() << mImage.format() << blitImage.format(); - GLuint shaderProgram = QOpenKODEGraphicsSystem::blitterProgram(); + GLuint shaderProgram = QOpenKODEIntegration::blitterProgram(); glUseProgram(shaderProgram); @@ -201,14 +129,13 @@ void QOpenKODEWindowSurface::flush(QWidget *, const QRegion ®ion, const QPoin GLfloat texcoords[8] = { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0 }; // Generate texture for checkered background - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glGenTextures(1, &texId); glBindTexture(GL_TEXTURE_2D, texId); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, blitImage.bits()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, blitImage.bits()); // Enable vertex attribute associated with vertex position glEnableVertexAttribArray(posId); @@ -230,31 +157,26 @@ void QOpenKODEWindowSurface::flush(QWidget *, const QRegion ®ion, const QPoin if (texId) glDeleteTextures(1, &texId); - mContext.doneCurrent(); mContext.swapBuffers(mSurface); + mContext.doneCurrent(); } -void QOpenKODEWindowSurface::setGeometry(const QRect &rect) +void QOpenKODEWindowSurface::resize(const QSize &size) { - qDebug() << "QOpenKODEWindowSurface::setGeometry:" << rect; - QWindowSurface::setGeometry(rect); - if (mImage.size() != rect.size()) - mImage = QImage(rect.size(), mScreen->format()); - + QWindowSurface::resize(size); mContext.destroySurface(mSurface); - kdDestroyWindow(kdWindow); - createWindow(window()); - qDebug() << "set geometry workded"; -} + mSurface = EGL_NO_SURFACE; + mImage = QImage(); -bool QOpenKODEWindowSurface::scroll(const QRegion &area, int dx, int dy) -{ - return QWindowSurface::scroll(area, dx, dy); } - void QOpenKODEWindowSurface::beginPaint(const QRegion ®ion) { - Q_UNUSED(region); + if (mSurface == EGL_NO_SURFACE) { + EGLConfig config = QEgl::defaultConfig(QInternal::Widget,QEgl::OpenGL,QEgl::Renderable); + EGLint windowAttrs[] = { EGL_NONE }; + mSurface = eglCreateWindowSurface(QEgl::display(), config, mWin, windowAttrs); + mImage = QImage(size(),QImage::Format_RGB32); + } } void QOpenKODEWindowSurface::endPaint(const QRegion ®ion) diff --git a/src/plugins/platforms/openkode/qwindowsurface_openkode.h b/src/plugins/platforms/openkode/qopenkodewindowsurface.h index bee94a5..568dbc2 100644 --- a/src/plugins/platforms/openkode/qwindowsurface_openkode.h +++ b/src/plugins/platforms/openkode/qopenkodewindowsurface.h @@ -47,31 +47,27 @@ QT_BEGIN_NAMESPACE -class QOpenKODEGraphicsSystemScreen; +class QOpenKODEWindow; class QOpenKODEWindowSurface : public QWindowSurface { public: QOpenKODEWindowSurface - (QOpenKODEGraphicsSystemScreen *screen, QWidget *window); + (QWidget *window, WId winId); ~QOpenKODEWindowSurface(); QPaintDevice *paintDevice(); void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - void setGeometry(const QRect &rect); - bool scroll(const QRegion &area, int dx, int dy); + void resize (const QSize &size); void beginPaint(const QRegion ®ion); void endPaint(const QRegion ®ion); private: - QOpenKODEGraphicsSystemScreen *mScreen; QImage mImage; - struct KDWindow *kdWindow; - EGLSurface *mSurface; + EGLSurface mSurface; QEglContext mContext; - - void createWindow(QWidget *window); + EGLNativeWindowType mWin; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/openkode/resources.qrc b/src/plugins/platforms/openkode/resources.qrc new file mode 100644 index 0000000..dbb3419 --- /dev/null +++ b/src/plugins/platforms/openkode/resources.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>shaders/vert.glslv</file> + <file>shaders/frag.glslf</file> +</qresource> +</RCC> diff --git a/src/plugins/platforms/openkode/frag.glslf b/src/plugins/platforms/openkode/shaders/frag.glslf index a593434..ed360fe 100644 --- a/src/plugins/platforms/openkode/frag.glslf +++ b/src/plugins/platforms/openkode/shaders/frag.glslf @@ -2,7 +2,7 @@ uniform sampler2D tex_samp; varying vec2 texcoord_var; -void main() +void main(void) { gl_FragColor = texture2D(tex_samp, texcoord_var); } diff --git a/src/plugins/platforms/openkode/vert.glslv b/src/plugins/platforms/openkode/shaders/vert.glslv index 57b5866..57b5866 100644 --- a/src/plugins/platforms/openkode/vert.glslv +++ b/src/plugins/platforms/openkode/shaders/vert.glslv diff --git a/src/plugins/platforms/openkode/vert.h b/src/plugins/platforms/openkode/vert.h deleted file mode 100644 index bdf564d..0000000 --- a/src/plugins/platforms/openkode/vert.h +++ /dev/null @@ -1,63 +0,0 @@ -0x4e,0x56,0x75,0x63,0x01,0x00,0x00,0x00,0x0a,0x00,0x06,0x00,0x06,0x00,0x50,0x00, -0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0xf0,0x03,0x00,0x00,0x00,0x00,0x00,0x00, -0x03,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x60,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x24,0x00,0x00,0x00,0x0a,0x00,0x00,0x00,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x05,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x26,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x90,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0xe8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x06,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0xb0,0x01,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x28,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00, -0x05,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x10,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x20,0x02,0x00,0x00,0x00,0x00,0x00,0x00, -0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x01,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x30,0x02,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x2b,0x00,0x00,0x00,0x39,0x01,0x00,0x00,0xb0,0x02,0x00,0x00,0x00,0x00,0x00,0x00, -0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x30,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x04,0x05,0x08,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x0f,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x01,0x02,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, -0xff,0xff,0xff,0xff,0x04,0x05,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, -0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, -0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, -0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0x40,0x00,0x00,0x80,0xbf,0x00,0x00,0x00,0x00, -0x05,0x00,0x00,0x10,0x80,0xc7,0x00,0x24,0x05,0x02,0x00,0x10,0x80,0xc7,0x00,0x24, -0x01,0x02,0x81,0xc0,0x80,0x07,0x60,0x00,0x05,0x02,0x00,0x90,0x80,0x07,0x00,0x00, -0x09,0x00,0x01,0xe1,0x80,0x87,0x40,0x00,0x05,0x00,0x00,0x10,0x80,0xc7,0x00,0x24, -0x01,0x00,0x81,0xc0,0x80,0x07,0x60,0x00,0x09,0x04,0x00,0xa0,0x80,0x47,0x00,0xe4, -0x05,0x02,0x00,0x90,0x80,0x07,0x00,0x00,0x05,0x04,0x00,0x10,0x88,0xc7,0x03,0x04, -0x01,0x00,0x01,0xe1,0x88,0x87,0x40,0x00,0x09,0xf8,0x00,0x10,0x88,0xc7,0x03,0x04, -0x0d,0x00,0x00,0x10,0x88,0xc7,0x40,0x24,0x11,0x04,0x00,0x10,0x88,0xc7,0x23,0x04, -0x15,0x06,0x00,0x10,0x89,0xc7,0x23,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, -0xa0,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xa1,0x03,0x00,0x00,0x00,0x00,0x00,0x00, -0xad,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0x28,0x00,0x02,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00, -0xb6,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xb7,0x03,0x00,0x00,0x00,0x00,0x00,0x00, -0xbe,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x26,0x00,0x05,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, -0xbf,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x03,0x00,0x00,0x00,0x00,0x00,0x00, -0xc9,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x26,0x00,0x01,0x00,0x00,0x00, -0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, -0xca,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xcb,0x03,0x00,0x00,0x00,0x00,0x00,0x00, -0xd9,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x26,0x00,0x01,0x00,0x00,0x00, -0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, -0xda,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xdb,0x03,0x00,0x00,0x00,0x00,0x00,0x00, -0xe8,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x26,0x00,0x02,0x00,0x00,0x00, -0x04,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, -0x00,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0x50,0x4f,0x53, -0x49,0x54,0x49,0x4f,0x4e,0x00,0x00,0x77,0x69,0x6e,0x64,0x6f,0x77,0x00,0x00,0x00, -0x70,0x6f,0x73,0x5f,0x61,0x74,0x74,0x72,0x00,0x00,0x00,0x74,0x65,0x78,0x63,0x6f, -0x6f,0x72,0x64,0x5f,0x61,0x74,0x74,0x72,0x00,0x00,0x00,0x74,0x65,0x78,0x63,0x6f, -0x6f,0x72,0x64,0x5f,0x76,0x61,0x72,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 |