From f3ae27721ad0e71923e8538370731f91acb53601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Mon, 26 Jul 2010 09:34:10 +0200 Subject: Renamed files in EGLFS platform plugin --- src/plugins/platforms/eglfs/eglfs.pro | 16 + src/plugins/platforms/eglfs/eglintegration.cpp | 469 ---------------------- src/plugins/platforms/eglfs/eglintegration.h | 70 ---- src/plugins/platforms/eglfs/eglintegration.pro | 14 - src/plugins/platforms/eglfs/main.cpp | 2 +- src/plugins/platforms/eglfs/qeglfsintegration.cpp | 469 ++++++++++++++++++++++ src/plugins/platforms/eglfs/qeglfsintegration.h | 70 ++++ 7 files changed, 556 insertions(+), 554 deletions(-) create mode 100644 src/plugins/platforms/eglfs/eglfs.pro delete mode 100644 src/plugins/platforms/eglfs/eglintegration.cpp delete mode 100644 src/plugins/platforms/eglfs/eglintegration.h delete mode 100644 src/plugins/platforms/eglfs/eglintegration.pro create mode 100644 src/plugins/platforms/eglfs/qeglfsintegration.cpp create mode 100644 src/plugins/platforms/eglfs/qeglfsintegration.h diff --git a/src/plugins/platforms/eglfs/eglfs.pro b/src/plugins/platforms/eglfs/eglfs.pro new file mode 100644 index 0000000..2cc5997 --- /dev/null +++ b/src/plugins/platforms/eglfs/eglfs.pro @@ -0,0 +1,16 @@ +TARGET = qeglfs +TEMPLATE = lib +CONFIG += plugin + +QT += opengl + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms + +SOURCES = main.cpp \ + qeglfsintegration.cpp \ + ../eglconvenience/qeglconvenience.cpp +HEADERS = qeglfsintegration.h \ + ../eglconvenience/qeglconvenience.h + +target.path += $$[QT_INSTALL_PLUGINS]/platforms +INSTALLS += target diff --git a/src/plugins/platforms/eglfs/eglintegration.cpp b/src/plugins/platforms/eglfs/eglintegration.cpp deleted file mode 100644 index 9470c99..0000000 --- a/src/plugins/platforms/eglfs/eglintegration.cpp +++ /dev/null @@ -1,469 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "eglintegration.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "../eglconvenience/qeglconvenience.h" - -//#define QEGL_EXTRA_DEBUG -#ifdef QEGL_EXTRA_DEBUG -struct AttrInfo { EGLint attr; const char *name; }; -static struct AttrInfo attrs[] = { - {EGL_BUFFER_SIZE, "EGL_BUFFER_SIZE"}, - {EGL_ALPHA_SIZE, "EGL_ALPHA_SIZE"}, - {EGL_BLUE_SIZE, "EGL_BLUE_SIZE"}, - {EGL_GREEN_SIZE, "EGL_GREEN_SIZE"}, - {EGL_RED_SIZE, "EGL_RED_SIZE"}, - {EGL_DEPTH_SIZE, "EGL_DEPTH_SIZE"}, - {EGL_STENCIL_SIZE, "EGL_STENCIL_SIZE"}, - {EGL_CONFIG_CAVEAT, "EGL_CONFIG_CAVEAT"}, - {EGL_CONFIG_ID, "EGL_CONFIG_ID"}, - {EGL_LEVEL, "EGL_LEVEL"}, - {EGL_MAX_PBUFFER_HEIGHT, "EGL_MAX_PBUFFER_HEIGHT"}, - {EGL_MAX_PBUFFER_PIXELS, "EGL_MAX_PBUFFER_PIXELS"}, - {EGL_MAX_PBUFFER_WIDTH, "EGL_MAX_PBUFFER_WIDTH"}, - {EGL_NATIVE_RENDERABLE, "EGL_NATIVE_RENDERABLE"}, - {EGL_NATIVE_VISUAL_ID, "EGL_NATIVE_VISUAL_ID"}, - {EGL_NATIVE_VISUAL_TYPE, "EGL_NATIVE_VISUAL_TYPE"}, - {EGL_SAMPLES, "EGL_SAMPLES"}, - {EGL_SAMPLE_BUFFERS, "EGL_SAMPLE_BUFFERS"}, - {EGL_SURFACE_TYPE, "EGL_SURFACE_TYPE"}, - {EGL_TRANSPARENT_TYPE, "EGL_TRANSPARENT_TYPE"}, - {EGL_TRANSPARENT_BLUE_VALUE, "EGL_TRANSPARENT_BLUE_VALUE"}, - {EGL_TRANSPARENT_GREEN_VALUE, "EGL_TRANSPARENT_GREEN_VALUE"}, - {EGL_TRANSPARENT_RED_VALUE, "EGL_TRANSPARENT_RED_VALUE"}, - {EGL_BIND_TO_TEXTURE_RGB, "EGL_BIND_TO_TEXTURE_RGB"}, - {EGL_BIND_TO_TEXTURE_RGBA, "EGL_BIND_TO_TEXTURE_RGBA"}, - {EGL_MIN_SWAP_INTERVAL, "EGL_MIN_SWAP_INTERVAL"}, - {EGL_MAX_SWAP_INTERVAL, "EGL_MAX_SWAP_INTERVAL"}, - {-1, 0}}; -#endif //QEGL_EXTRA_DEBUG - - -class QEglScreen; - -class QEglContext : public QPlatformGLContext -{ -public: - QEglContext(QGLFormat& format, QPlatformGLContext* shareContext = 0); - ~QEglContext(); - - virtual void makeCurrent(); - virtual void doneCurrent(); - virtual void swapBuffers(); - virtual void* getProcAddress(const QString& procName); - - EGLContext eglContext() {return m_context;} - QSize size() const { return m_size; } - - QGLFormat format() const { return m_format; } -private: - - EGLContext m_context; - EGLDisplay m_dpy; - EGLSurface m_surface; - QSize m_size; - static bool singleton_watch; - QGLFormat m_format; -}; - -bool QEglContext::singleton_watch = false; - -QEglContext::QEglContext(QGLFormat& format, QPlatformGLContext* shareContext) -{ - if (singleton_watch) - qFatal("There can be only one"); - singleton_watch = true; - - Q_UNUSED(shareContext); - Q_UNUSED(format); - - EGLint major, minor; -#ifdef QEGL_EXTRA_DEBUG - EGLint index; -#endif - if (!eglBindAPI(EGL_OPENGL_ES_API)) { - fprintf(stderr, "Could not bind GL_ES API\n"); - qFatal("EGL error"); - } - - m_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (m_dpy == EGL_NO_DISPLAY) { - fprintf(stderr, "Could not open egl display\n"); - qFatal("EGL error"); - } - fprintf(stderr, "Opened display %p\n", m_dpy); - - if (!eglInitialize(m_dpy, &major, &minor)) { - fprintf(stderr, "Could not initialize egl display\n"); - qFatal("EGL error"); - } - - fprintf(stderr, "Initialized display %d %d\n", major, minor); - - QPlatformWindowFormat platformFormat; - platformFormat.setDepth(16); - platformFormat.setWindowApi(QPlatformWindowFormat::OpenGL); - platformFormat.setRedBufferSize(5); - platformFormat.setGreenBufferSize(6); - platformFormat.setBlueBufferSize(5); - EGLConfig config = q_configFromQPlatformWindowFormat(m_dpy, platformFormat); - -#ifdef QEGL_EXTRA_DEBUG - fprintf(stderr, "Configuration %d matches requirements\n", (int)config); - - for (index = 0; attrs[index].attr != -1; ++index) { - EGLint value; - if (eglGetConfigAttrib(m_dpy, config, attrs[index].attr, &value)) { - printf("\t%s: %d\n", attrs[index].name, (int)value); - } - } - printf("\n"); -#endif - EGLint temp; - EGLint attribList[32]; - - temp = 0; - - attribList[temp++] = EGL_CONTEXT_CLIENT_VERSION; - attribList[temp++] = 2; // GLES version 2 - attribList[temp++] = EGL_NONE; - - - m_context = eglCreateContext(m_dpy, config, NULL, attribList); - if (m_context == EGL_NO_CONTEXT) { - fprintf(stderr, "Could not create the egl context\n"); - eglTerminate(m_dpy); - qFatal("EGL error"); - } - - m_surface = eglCreateWindowSurface(m_dpy, config, 0, NULL); - if (m_surface == EGL_NO_SURFACE) { - fprintf(stderr, "Could not create the egl surface: error = 0x%x\n", eglGetError()); - eglTerminate(m_dpy); - qFatal("EGL error"); - } - - EGLint w,h; - - eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w); - eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h); - fprintf(stderr, "Created surface %dx%d\n", w, h); - - m_size = QSize(w,h); - - -} - -QEglContext::~QEglContext() -{ -#ifdef QEGL_EXTRA_DEBUG - qDebug() << "QEglContext::~QEglContext()"; -#endif -} - -void QEglContext::makeCurrent() -{ -#ifdef QEGL_EXTRA_DEBUG - fprintf(stderr, "QEglContext::makeCurrent\n"); -#endif - if (!eglMakeCurrent(m_dpy, m_surface, m_surface, m_context)) - fprintf(stderr, "Could not make the egl context current\n"); - -#ifdef QEGL_EXTRA_DEBUG - static bool showDebug = true; - if (showDebug) { - showDebug = false; - const char *str = (const char*)glGetString(GL_VENDOR); - qDebug() << "Vendor" << str; - printf("Vendor %s\n", str); - str = (const char*)glGetString(GL_RENDERER); - qDebug() << "Renderer" << str; - printf("Renderer %s\n", str); - str = (const char*)glGetString(GL_VERSION); - qDebug() << "Version" << str; - printf("Version %s\n", str); - - str = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); - qDebug() << "Shader version" << str; - - str = (const char*)glGetString(GL_EXTENSIONS); - qDebug() << "Extensions" << str; - printf("Extensions %s\n", str); - - } -#endif -} - -void QEglContext::doneCurrent() -{ -#ifdef QEGL_EXTRA_DEBUG - fprintf(stderr, "QEglContext::doneCurrent\n"); -#endif - if (!eglMakeCurrent(m_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) - fprintf(stderr, "Could not release the egl context\n"); -} - -void QEglContext::swapBuffers() -{ -#ifdef QEGL_EXTRA_DEBUG - fprintf(stderr, "QEglContext::swapBuffers\n"); -#endif - eglSwapBuffers(m_dpy, m_surface); -} - -void* QEglContext::getProcAddress(const QString& procName) -{ -#ifdef QEGL_EXTRA_DEBUG - fprintf(stderr, "QEglContext::getProcAddress\n"); -#endif - return (void*)eglGetProcAddress(qPrintable(procName)); -} - - -class QEglPaintDevice; -class QEglScreen : public QPlatformScreen -{ -public: - QEglScreen(); - ~QEglScreen() {} - - QRect geometry() const { return m_geometry; } - int depth() const { return m_depth; } - QImage::Format format() const { return m_format; } - //QSize physicalSize() const { return m_physicalSize; } //### - -public: - QRect m_geometry; - int m_depth; - QImage::Format m_format; - //QSize m_physicalSize; - QEglContext * m_platformContext; -}; - - -class QEglWindow : public QPlatformWindow -{ -public: - QEglWindow(QWidget *w, QEglScreen *screen); - QPlatformGLContext *glContext(); - - void setGeometry(const QRect &); - WId winId() const; - - QGLContext *context() { return m_context; } - QEglPaintDevice *paintDevice() { return m_pd; } -private: - QEglScreen *m_screen; - QEglPaintDevice *m_pd; - QGLContext *m_context; - WId m_winid; -}; - -class QEglPaintDevice : public QGLPaintDevice -{ -public: - QEglPaintDevice(QEglScreen *screen, QEglWindow *window); - - QSize size() const { return m_screen->geometry().size(); } - QGLContext* context() const { return m_window->context();} - - QPaintEngine *paintEngine() const { return qt_qgl_paint_engine(); } - - void beginPaint(){ - QGLPaintDevice::beginPaint(); - } -private: - QEglScreen *m_screen; - QEglWindow * m_window; -}; - - - - -QEglScreen::QEglScreen() - : m_depth(16), m_format(QImage::Format_RGB16), m_platformContext(0) -{ -#ifdef QEGL_EXTRA_DEBUG - fprintf(stderr, "QEglScreen %p\n", this); -#endif - QGLFormat format = QGLFormat::defaultFormat(); - m_platformContext = new QEglContext(format); - - - m_geometry = QRect(QPoint(), m_platformContext->size()); - -} - - - - -QEglPaintDevice::QEglPaintDevice(QEglScreen *screen, QEglWindow *window) - :QGLPaintDevice(), m_screen(screen), m_window(window) -{ -#ifdef QEGL_EXTRA_DEBUG - qDebug() << "QEglPaintDevice" << this << screen << window; -#endif -} - - - -QEglWindow::QEglWindow(QWidget *w, QEglScreen *screen) - : QPlatformWindow(w), m_screen(screen), m_pd(0), m_context(0) -{ - static int serialNo = 0; - m_winid = ++serialNo; -#ifdef QEGL_EXTRA_DEBUG - fprintf(stderr, "QEglWindow %p: %p %p 0x%x\n", this, w, screen, uint(m_winid)); -#endif - m_pd = new QEglPaintDevice(screen, this); - m_context = new QGLContext( screen->m_platformContext->format(), w); - m_context->create(); -} - - -void QEglWindow::setGeometry(const QRect &) -{ - // We only support full-screen windows - QRect rect(m_screen->availableGeometry()); - QWindowSystemInterface::handleGeometryChange(this->widget(), rect); - - QPlatformWindow::setGeometry(rect); -} - -WId QEglWindow::winId() const -{ - return m_winid; -} - - - -QPlatformGLContext *QEglWindow::glContext() -{ -#ifdef QEGL_EXTRA_DEBUG - fprintf(stderr, "QEglWindow::glContext %p\n", m_screen->m_platformContext); -#endif - Q_ASSERT(m_screen); - return m_screen->m_platformContext; -} - -QEglIntegration::QEglIntegration() -{ - m_primaryScreen = new QEglScreen(); - - mScreens.append(m_primaryScreen); -#ifdef QEGL_EXTRA_DEBUG - fprintf(stderr, "QEglIntegration\n"); -#endif -} - -QPixmapData *QEglIntegration::createPixmapData(QPixmapData::PixelType type) const -{ -#ifdef QEGL_EXTRA_DEBUG - fprintf(stderr, "QEglIntegration::createPixmapData %d\n", type); -#endif - return new QGLPixmapData(type); -} - -QPlatformWindow *QEglIntegration::createPlatformWindow(QWidget *widget, WId winId) const -{ - Q_UNUSED(winId); -#ifdef QEGL_EXTRA_DEBUG - qDebug() << "QEglIntegration::createPlatformWindow" << widget; -#endif - return new QEglWindow(widget, m_primaryScreen); -} - - -class QEglWindowSurface : public QWindowSurface -{ -public: - QEglWindowSurface(QWidget *window, QEglScreen *screen); - ~QEglWindowSurface() {} - - QPaintDevice *paintDevice() { return m_window->paintDevice(); } - void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - void resize(const QSize &size) {} -private: - QEglScreen *m_screen; - QEglWindow *m_window; -}; - -QEglWindowSurface::QEglWindowSurface(QWidget *window, QEglScreen *screen) - :QWindowSurface(window), m_screen(screen), m_window(0) -{ -#ifdef QEGL_EXTRA_DEBUG - qDebug() << "QEglWindowSurface" << window << screen; -#endif - m_window = static_cast(window->platformWindow()); -} - - -void QEglWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) -{ - Q_UNUSED(widget); - Q_UNUSED(region); - Q_UNUSED(offset); -#ifdef QEGL_EXTRA_DEBUG - qDebug() << "QEglWindowSurface::flush"; -#endif - m_screen->m_platformContext->swapBuffers(); -} - -QWindowSurface *QEglIntegration::createWindowSurface(QWidget *widget, WId winId) const -{ - Q_UNUSED(winId); - -#ifdef QEGL_EXTRA_DEBUG - qDebug() << "QEglIntegration::createWindowSurface" << widget; -#endif - return new QEglWindowSurface(widget, m_primaryScreen); -} diff --git a/src/plugins/platforms/eglfs/eglintegration.h b/src/plugins/platforms/eglfs/eglintegration.h deleted file mode 100644 index 7b9b8cf..0000000 --- a/src/plugins/platforms/eglfs/eglintegration.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Technology Preview License Agreement accompanying -** this package. -** -** 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.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef EGLINTEGRATION_H -#define EGLINTEGRATION_H - -#include -#include - -QT_BEGIN_NAMESPACE - -class QEglScreen; -class QEglIntegration : public QPlatformIntegration -{ -public: - QEglIntegration(); - - QPixmapData *createPixmapData(QPixmapData::PixelType type) const; - QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; - QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; - - QList screens() const { return mScreens; } - -private: - QList mScreens; - QEglScreen *m_primaryScreen; -}; - -QT_END_NAMESPACE - - -#endif diff --git a/src/plugins/platforms/eglfs/eglintegration.pro b/src/plugins/platforms/eglfs/eglintegration.pro deleted file mode 100644 index 7cd2f05..0000000 --- a/src/plugins/platforms/eglfs/eglintegration.pro +++ /dev/null @@ -1,14 +0,0 @@ -TARGET = eglintegration -TEMPLATE = lib -CONFIG += plugin - -QT += opengl - -SOURCES = main.cpp \ - eglintegration.cpp \ - ../eglconvenience/qeglconvenience.cpp -HEADERS = eglintegration.h \ - ../eglconvenience/qeglconvenience.h - -target.path += $$[QT_INSTALL_PLUGINS]/platforms -INSTALLS += target diff --git a/src/plugins/platforms/eglfs/main.cpp b/src/plugins/platforms/eglfs/main.cpp index adaea78..e1731e8 100644 --- a/src/plugins/platforms/eglfs/main.cpp +++ b/src/plugins/platforms/eglfs/main.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include -#include "eglintegration.h" +#include "qeglfsintegration.h" QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/eglfs/qeglfsintegration.cpp b/src/plugins/platforms/eglfs/qeglfsintegration.cpp new file mode 100644 index 0000000..4d17980 --- /dev/null +++ b/src/plugins/platforms/eglfs/qeglfsintegration.cpp @@ -0,0 +1,469 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qeglfsintegration.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "../eglconvenience/qeglconvenience.h" + +//#define QEGL_EXTRA_DEBUG +#ifdef QEGL_EXTRA_DEBUG +struct AttrInfo { EGLint attr; const char *name; }; +static struct AttrInfo attrs[] = { + {EGL_BUFFER_SIZE, "EGL_BUFFER_SIZE"}, + {EGL_ALPHA_SIZE, "EGL_ALPHA_SIZE"}, + {EGL_BLUE_SIZE, "EGL_BLUE_SIZE"}, + {EGL_GREEN_SIZE, "EGL_GREEN_SIZE"}, + {EGL_RED_SIZE, "EGL_RED_SIZE"}, + {EGL_DEPTH_SIZE, "EGL_DEPTH_SIZE"}, + {EGL_STENCIL_SIZE, "EGL_STENCIL_SIZE"}, + {EGL_CONFIG_CAVEAT, "EGL_CONFIG_CAVEAT"}, + {EGL_CONFIG_ID, "EGL_CONFIG_ID"}, + {EGL_LEVEL, "EGL_LEVEL"}, + {EGL_MAX_PBUFFER_HEIGHT, "EGL_MAX_PBUFFER_HEIGHT"}, + {EGL_MAX_PBUFFER_PIXELS, "EGL_MAX_PBUFFER_PIXELS"}, + {EGL_MAX_PBUFFER_WIDTH, "EGL_MAX_PBUFFER_WIDTH"}, + {EGL_NATIVE_RENDERABLE, "EGL_NATIVE_RENDERABLE"}, + {EGL_NATIVE_VISUAL_ID, "EGL_NATIVE_VISUAL_ID"}, + {EGL_NATIVE_VISUAL_TYPE, "EGL_NATIVE_VISUAL_TYPE"}, + {EGL_SAMPLES, "EGL_SAMPLES"}, + {EGL_SAMPLE_BUFFERS, "EGL_SAMPLE_BUFFERS"}, + {EGL_SURFACE_TYPE, "EGL_SURFACE_TYPE"}, + {EGL_TRANSPARENT_TYPE, "EGL_TRANSPARENT_TYPE"}, + {EGL_TRANSPARENT_BLUE_VALUE, "EGL_TRANSPARENT_BLUE_VALUE"}, + {EGL_TRANSPARENT_GREEN_VALUE, "EGL_TRANSPARENT_GREEN_VALUE"}, + {EGL_TRANSPARENT_RED_VALUE, "EGL_TRANSPARENT_RED_VALUE"}, + {EGL_BIND_TO_TEXTURE_RGB, "EGL_BIND_TO_TEXTURE_RGB"}, + {EGL_BIND_TO_TEXTURE_RGBA, "EGL_BIND_TO_TEXTURE_RGBA"}, + {EGL_MIN_SWAP_INTERVAL, "EGL_MIN_SWAP_INTERVAL"}, + {EGL_MAX_SWAP_INTERVAL, "EGL_MAX_SWAP_INTERVAL"}, + {-1, 0}}; +#endif //QEGL_EXTRA_DEBUG + + +class QEglScreen; + +class QEglContext : public QPlatformGLContext +{ +public: + QEglContext(QGLFormat& format, QPlatformGLContext* shareContext = 0); + ~QEglContext(); + + virtual void makeCurrent(); + virtual void doneCurrent(); + virtual void swapBuffers(); + virtual void* getProcAddress(const QString& procName); + + EGLContext eglContext() {return m_context;} + QSize size() const { return m_size; } + + QGLFormat format() const { return m_format; } +private: + + EGLContext m_context; + EGLDisplay m_dpy; + EGLSurface m_surface; + QSize m_size; + static bool singleton_watch; + QGLFormat m_format; +}; + +bool QEglContext::singleton_watch = false; + +QEglContext::QEglContext(QGLFormat& format, QPlatformGLContext* shareContext) +{ + if (singleton_watch) + qFatal("There can be only one"); + singleton_watch = true; + + Q_UNUSED(shareContext); + Q_UNUSED(format); + + EGLint major, minor; +#ifdef QEGL_EXTRA_DEBUG + EGLint index; +#endif + if (!eglBindAPI(EGL_OPENGL_ES_API)) { + fprintf(stderr, "Could not bind GL_ES API\n"); + qFatal("EGL error"); + } + + m_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (m_dpy == EGL_NO_DISPLAY) { + fprintf(stderr, "Could not open egl display\n"); + qFatal("EGL error"); + } + fprintf(stderr, "Opened display %p\n", m_dpy); + + if (!eglInitialize(m_dpy, &major, &minor)) { + fprintf(stderr, "Could not initialize egl display\n"); + qFatal("EGL error"); + } + + fprintf(stderr, "Initialized display %d %d\n", major, minor); + + QPlatformWindowFormat platformFormat; + platformFormat.setDepth(16); + platformFormat.setWindowApi(QPlatformWindowFormat::OpenGL); + platformFormat.setRedBufferSize(5); + platformFormat.setGreenBufferSize(6); + platformFormat.setBlueBufferSize(5); + EGLConfig config = q_configFromQPlatformWindowFormat(m_dpy, platformFormat); + +#ifdef QEGL_EXTRA_DEBUG + fprintf(stderr, "Configuration %d matches requirements\n", (int)config); + + for (index = 0; attrs[index].attr != -1; ++index) { + EGLint value; + if (eglGetConfigAttrib(m_dpy, config, attrs[index].attr, &value)) { + printf("\t%s: %d\n", attrs[index].name, (int)value); + } + } + printf("\n"); +#endif + EGLint temp; + EGLint attribList[32]; + + temp = 0; + + attribList[temp++] = EGL_CONTEXT_CLIENT_VERSION; + attribList[temp++] = 2; // GLES version 2 + attribList[temp++] = EGL_NONE; + + + m_context = eglCreateContext(m_dpy, config, NULL, attribList); + if (m_context == EGL_NO_CONTEXT) { + fprintf(stderr, "Could not create the egl context\n"); + eglTerminate(m_dpy); + qFatal("EGL error"); + } + + m_surface = eglCreateWindowSurface(m_dpy, config, 0, NULL); + if (m_surface == EGL_NO_SURFACE) { + fprintf(stderr, "Could not create the egl surface: error = 0x%x\n", eglGetError()); + eglTerminate(m_dpy); + qFatal("EGL error"); + } + + EGLint w,h; + + eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w); + eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h); + fprintf(stderr, "Created surface %dx%d\n", w, h); + + m_size = QSize(w,h); + + +} + +QEglContext::~QEglContext() +{ +#ifdef QEGL_EXTRA_DEBUG + qDebug() << "QEglContext::~QEglContext()"; +#endif +} + +void QEglContext::makeCurrent() +{ +#ifdef QEGL_EXTRA_DEBUG + fprintf(stderr, "QEglContext::makeCurrent\n"); +#endif + if (!eglMakeCurrent(m_dpy, m_surface, m_surface, m_context)) + fprintf(stderr, "Could not make the egl context current\n"); + +#ifdef QEGL_EXTRA_DEBUG + static bool showDebug = true; + if (showDebug) { + showDebug = false; + const char *str = (const char*)glGetString(GL_VENDOR); + qDebug() << "Vendor" << str; + printf("Vendor %s\n", str); + str = (const char*)glGetString(GL_RENDERER); + qDebug() << "Renderer" << str; + printf("Renderer %s\n", str); + str = (const char*)glGetString(GL_VERSION); + qDebug() << "Version" << str; + printf("Version %s\n", str); + + str = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); + qDebug() << "Shader version" << str; + + str = (const char*)glGetString(GL_EXTENSIONS); + qDebug() << "Extensions" << str; + printf("Extensions %s\n", str); + + } +#endif +} + +void QEglContext::doneCurrent() +{ +#ifdef QEGL_EXTRA_DEBUG + fprintf(stderr, "QEglContext::doneCurrent\n"); +#endif + if (!eglMakeCurrent(m_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) + fprintf(stderr, "Could not release the egl context\n"); +} + +void QEglContext::swapBuffers() +{ +#ifdef QEGL_EXTRA_DEBUG + fprintf(stderr, "QEglContext::swapBuffers\n"); +#endif + eglSwapBuffers(m_dpy, m_surface); +} + +void* QEglContext::getProcAddress(const QString& procName) +{ +#ifdef QEGL_EXTRA_DEBUG + fprintf(stderr, "QEglContext::getProcAddress\n"); +#endif + return (void*)eglGetProcAddress(qPrintable(procName)); +} + + +class QEglPaintDevice; +class QEglScreen : public QPlatformScreen +{ +public: + QEglScreen(); + ~QEglScreen() {} + + QRect geometry() const { return m_geometry; } + int depth() const { return m_depth; } + QImage::Format format() const { return m_format; } + //QSize physicalSize() const { return m_physicalSize; } //### + +public: + QRect m_geometry; + int m_depth; + QImage::Format m_format; + //QSize m_physicalSize; + QEglContext * m_platformContext; +}; + + +class QEglWindow : public QPlatformWindow +{ +public: + QEglWindow(QWidget *w, QEglScreen *screen); + QPlatformGLContext *glContext(); + + void setGeometry(const QRect &); + WId winId() const; + + QGLContext *context() { return m_context; } + QEglPaintDevice *paintDevice() { return m_pd; } +private: + QEglScreen *m_screen; + QEglPaintDevice *m_pd; + QGLContext *m_context; + WId m_winid; +}; + +class QEglPaintDevice : public QGLPaintDevice +{ +public: + QEglPaintDevice(QEglScreen *screen, QEglWindow *window); + + QSize size() const { return m_screen->geometry().size(); } + QGLContext* context() const { return m_window->context();} + + QPaintEngine *paintEngine() const { return qt_qgl_paint_engine(); } + + void beginPaint(){ + QGLPaintDevice::beginPaint(); + } +private: + QEglScreen *m_screen; + QEglWindow * m_window; +}; + + + + +QEglScreen::QEglScreen() + : m_depth(16), m_format(QImage::Format_RGB16), m_platformContext(0) +{ +#ifdef QEGL_EXTRA_DEBUG + fprintf(stderr, "QEglScreen %p\n", this); +#endif + QGLFormat format = QGLFormat::defaultFormat(); + m_platformContext = new QEglContext(format); + + + m_geometry = QRect(QPoint(), m_platformContext->size()); + +} + + + + +QEglPaintDevice::QEglPaintDevice(QEglScreen *screen, QEglWindow *window) + :QGLPaintDevice(), m_screen(screen), m_window(window) +{ +#ifdef QEGL_EXTRA_DEBUG + qDebug() << "QEglPaintDevice" << this << screen << window; +#endif +} + + + +QEglWindow::QEglWindow(QWidget *w, QEglScreen *screen) + : QPlatformWindow(w), m_screen(screen), m_pd(0), m_context(0) +{ + static int serialNo = 0; + m_winid = ++serialNo; +#ifdef QEGL_EXTRA_DEBUG + fprintf(stderr, "QEglWindow %p: %p %p 0x%x\n", this, w, screen, uint(m_winid)); +#endif + m_pd = new QEglPaintDevice(screen, this); + m_context = new QGLContext( screen->m_platformContext->format(), w); + m_context->create(); +} + + +void QEglWindow::setGeometry(const QRect &) +{ + // We only support full-screen windows + QRect rect(m_screen->availableGeometry()); + QWindowSystemInterface::handleGeometryChange(this->widget(), rect); + + QPlatformWindow::setGeometry(rect); +} + +WId QEglWindow::winId() const +{ + return m_winid; +} + + + +QPlatformGLContext *QEglWindow::glContext() +{ +#ifdef QEGL_EXTRA_DEBUG + fprintf(stderr, "QEglWindow::glContext %p\n", m_screen->m_platformContext); +#endif + Q_ASSERT(m_screen); + return m_screen->m_platformContext; +} + +QEglIntegration::QEglIntegration() +{ + m_primaryScreen = new QEglScreen(); + + mScreens.append(m_primaryScreen); +#ifdef QEGL_EXTRA_DEBUG + fprintf(stderr, "QEglIntegration\n"); +#endif +} + +QPixmapData *QEglIntegration::createPixmapData(QPixmapData::PixelType type) const +{ +#ifdef QEGL_EXTRA_DEBUG + fprintf(stderr, "QEglIntegration::createPixmapData %d\n", type); +#endif + return new QGLPixmapData(type); +} + +QPlatformWindow *QEglIntegration::createPlatformWindow(QWidget *widget, WId winId) const +{ + Q_UNUSED(winId); +#ifdef QEGL_EXTRA_DEBUG + qDebug() << "QEglIntegration::createPlatformWindow" << widget; +#endif + return new QEglWindow(widget, m_primaryScreen); +} + + +class QEglWindowSurface : public QWindowSurface +{ +public: + QEglWindowSurface(QWidget *window, QEglScreen *screen); + ~QEglWindowSurface() {} + + QPaintDevice *paintDevice() { return m_window->paintDevice(); } + void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); + void resize(const QSize &size) {} +private: + QEglScreen *m_screen; + QEglWindow *m_window; +}; + +QEglWindowSurface::QEglWindowSurface(QWidget *window, QEglScreen *screen) + :QWindowSurface(window), m_screen(screen), m_window(0) +{ +#ifdef QEGL_EXTRA_DEBUG + qDebug() << "QEglWindowSurface" << window << screen; +#endif + m_window = static_cast(window->platformWindow()); +} + + +void QEglWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(widget); + Q_UNUSED(region); + Q_UNUSED(offset); +#ifdef QEGL_EXTRA_DEBUG + qDebug() << "QEglWindowSurface::flush"; +#endif + m_screen->m_platformContext->swapBuffers(); +} + +QWindowSurface *QEglIntegration::createWindowSurface(QWidget *widget, WId winId) const +{ + Q_UNUSED(winId); + +#ifdef QEGL_EXTRA_DEBUG + qDebug() << "QEglIntegration::createWindowSurface" << widget; +#endif + return new QEglWindowSurface(widget, m_primaryScreen); +} diff --git a/src/plugins/platforms/eglfs/qeglfsintegration.h b/src/plugins/platforms/eglfs/qeglfsintegration.h new file mode 100644 index 0000000..7b9b8cf --- /dev/null +++ b/src/plugins/platforms/eglfs/qeglfsintegration.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef EGLINTEGRATION_H +#define EGLINTEGRATION_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QEglScreen; +class QEglIntegration : public QPlatformIntegration +{ +public: + QEglIntegration(); + + QPixmapData *createPixmapData(QPixmapData::PixelType type) const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; + + QList screens() const { return mScreens; } + +private: + QList mScreens; + QEglScreen *m_primaryScreen; +}; + +QT_END_NAMESPACE + + +#endif -- cgit v0.12