diff options
author | Jørgen Lind <jorgen.lind@nokia.com> | 2010-11-23 14:34:09 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2010-11-24 08:54:48 (GMT) |
commit | 004cd14b84e3683cd92cf01061ee9688990f990c (patch) | |
tree | 8f879f07439b212de831c528e832d3c3ab4c6bb3 /src/plugins | |
parent | f309a20b4177572282082b8c17ec9025b75a69b1 (diff) | |
download | Qt-004cd14b84e3683cd92cf01061ee9688990f990c.zip Qt-004cd14b84e3683cd92cf01061ee9688990f990c.tar.gz Qt-004cd14b84e3683cd92cf01061ee9688990f990c.tar.bz2 |
Lighthouse: Fix QGLContext::currentContext for systems with limited
resources. The example plugins EGLFS uses only 1 native
context. Make sure that we only use this 1 context, and that we dont
wrap it in many different QPlatformGLContexts or QGLContexts instanses.
This change also removes the QPlatformWindow link which was made in the
initial QPlatformGLContext change. Lighthouse has to support situations
where a context isnt bound to a QPlatformWindow.
Reviewed-by: gunnar
Diffstat (limited to 'src/plugins')
8 files changed, 72 insertions, 32 deletions
diff --git a/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp b/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp index a169c35..c4adb6f 100644 --- a/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp +++ b/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp @@ -48,8 +48,8 @@ #include <EGL/egl.h> -QEGLPlatformContext::QEGLPlatformContext(EGLDisplay display, EGLConfig config, EGLint contextAttrs[], EGLSurface surface, EGLenum eglApi, QPlatformWindow *platformWindow) - : QPlatformGLContext(platformWindow) +QEGLPlatformContext::QEGLPlatformContext(EGLDisplay display, EGLConfig config, EGLint contextAttrs[], EGLSurface surface, EGLenum eglApi) + : QPlatformGLContext() , m_eglDisplay(display) , m_eglSurface(surface) , m_eglApi(eglApi) diff --git a/src/plugins/platforms/eglconvenience/qeglplatformcontext.h b/src/plugins/platforms/eglconvenience/qeglplatformcontext.h index 2c38aca..ae1a891 100644 --- a/src/plugins/platforms/eglconvenience/qeglplatformcontext.h +++ b/src/plugins/platforms/eglconvenience/qeglplatformcontext.h @@ -48,7 +48,7 @@ class QEGLPlatformContext : public QPlatformGLContext { public: - QEGLPlatformContext(EGLDisplay display, EGLConfig config, EGLint contextAttrs[], EGLSurface surface, EGLenum eglApi, QPlatformWindow *platformWindow); + QEGLPlatformContext(EGLDisplay display, EGLConfig config, EGLint contextAttrs[], EGLSurface surface, EGLenum eglApi); ~QEGLPlatformContext(); void makeCurrent(); diff --git a/src/plugins/platforms/eglfs/qeglfsscreen.cpp b/src/plugins/platforms/eglfs/qeglfsscreen.cpp index b9d1b17..7abc492 100644 --- a/src/plugins/platforms/eglfs/qeglfsscreen.cpp +++ b/src/plugins/platforms/eglfs/qeglfsscreen.cpp @@ -87,7 +87,10 @@ static struct AttrInfo attrs[] = { #endif //QEGL_EXTRA_DEBUG QEglFSScreen::QEglFSScreen(EGLNativeDisplayType display) - : m_depth(32), m_format(QImage::Format_ARGB32_Premultiplied), m_platformContext(0) + : m_depth(32) + , m_format(QImage::Format_Invalid) + , m_platformContext(0) + , m_surface(0) { #ifdef QEGL_EXTRA_DEBUG qWarning("QEglScreen %p\n", this); @@ -116,7 +119,25 @@ QEglFSScreen::QEglFSScreen(EGLNativeDisplayType display) qWarning("Initialized display %d %d\n", major, minor); - QPlatformWindowFormat platformFormat; + int swapInterval = 1; + QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL"); + if (!swapIntervalString.isEmpty()) { + bool ok; + swapInterval = swapIntervalString.toInt(&ok); + if (!ok) + swapInterval = 1; + } + eglSwapInterval(m_dpy, swapInterval); +} + +void QEglFSScreen::createAndSetPlatformContext() const { + const_cast<QEglFSScreen *>(this)->createAndSetPlatformContext(); +} + +void QEglFSScreen::createAndSetPlatformContext() +{ + QPlatformWindowFormat platformFormat = QPlatformWindowFormat::defaultFormat(); + platformFormat.setWindowApi(QPlatformWindowFormat::OpenGL); QByteArray depthString = qgetenv("QT_QPA_EGLFS_DEPTH"); @@ -132,23 +153,15 @@ QEglFSScreen::QEglFSScreen(EGLNativeDisplayType display) platformFormat.setRedBufferSize(8); platformFormat.setGreenBufferSize(8); platformFormat.setBlueBufferSize(8); + m_depth = 32; + m_format = QImage::Format_RGB32; } - if (!qgetenv("QT_QPA_EGLFS_MULTISAMPLE").isEmpty()) { platformFormat.setSampleBuffers(true); } - int swapInterval = 1; - QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL"); - if (!swapIntervalString.isEmpty()) { - bool ok; - swapInterval = swapIntervalString.toInt(&ok); - if (!ok) - swapInterval = 1; - } EGLConfig config = q_configFromQPlatformWindowFormat(m_dpy, platformFormat); - eglSwapInterval(display, swapInterval); EGLNativeWindowType eglWindow = 0; #ifdef Q_OPENKODE @@ -189,15 +202,42 @@ QEglFSScreen::QEglFSScreen(EGLNativeDisplayType display) attribList[temp++] = 2; // GLES version 2 attribList[temp++] = EGL_NONE; - m_platformContext = new QEGLPlatformContext(m_dpy,config,attribList,m_surface,EGL_OPENGL_ES_API, 0); - -// qWarning("Created platformcontext"); - EGLint w,h; + m_platformContext = new QEGLPlatformContext(m_dpy,config,attribList,m_surface,EGL_OPENGL_ES_API); + EGLint w,h; // screen size detection eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w); eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h); m_geometry = QRect(0,0,w,h); + +} + +QRect QEglFSScreen::geometry() const +{ + if (m_geometry.isNull()) { + createAndSetPlatformContext(); + } + return m_geometry; +} + +int QEglFSScreen::depth() const +{ + return m_depth; +} + +QImage::Format QEglFSScreen::format() const +{ + if (m_format == QImage::Format_Invalid) + createAndSetPlatformContext(); + return m_format; +} +QPlatformGLContext *QEglFSScreen::platformContext() const +{ + if (!m_platformContext) { + QEglFSScreen *that = const_cast<QEglFSScreen *>(this); + that->createAndSetPlatformContext(); + } + return m_platformContext; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/eglfs/qeglfsscreen.h b/src/plugins/platforms/eglfs/qeglfsscreen.h index 9ed1b04..bfbfa62 100644 --- a/src/plugins/platforms/eglfs/qeglfsscreen.h +++ b/src/plugins/platforms/eglfs/qeglfsscreen.h @@ -57,13 +57,16 @@ public: QEglFSScreen(EGLNativeDisplayType display); ~QEglFSScreen() {} - QRect geometry() const { return m_geometry; } - int depth() const { return m_depth; } - QImage::Format format() const { return m_format; } + QRect geometry() const; + int depth() const; + QImage::Format format() const; - QPlatformGLContext *platformContext() const { return m_platformContext; } + QPlatformGLContext *platformContext() const; private: + void createAndSetPlatformContext() const; + void createAndSetPlatformContext(); + QRect m_geometry; int m_depth; QImage::Format m_format; diff --git a/src/plugins/platforms/eglfs/qeglfswindowsurface.cpp b/src/plugins/platforms/eglfs/qeglfswindowsurface.cpp index fcea4d3..ebc04bd 100644 --- a/src/plugins/platforms/eglfs/qeglfswindowsurface.cpp +++ b/src/plugins/platforms/eglfs/qeglfswindowsurface.cpp @@ -57,13 +57,10 @@ public: #ifdef QEGL_EXTRA_DEBUG qWarning("QEglPaintDevice %p, %p, %p",this, screen, widget); #endif - QGLFormat format; - m_context = new QGLContext(format, widget); - m_context->create(); } QSize size() const { return m_screen->geometry().size(); } - QGLContext* context() const { return m_context;} + QGLContext* context() const { return QGLContext::fromPlatformGLContext(m_screen->platformContext());} QPaintEngine *paintEngine() const { return qt_qgl_paint_engine(); } diff --git a/src/plugins/platforms/testlite/qglxintegration.cpp b/src/plugins/platforms/testlite/qglxintegration.cpp index c35db9b..a4b7b69 100644 --- a/src/plugins/platforms/testlite/qglxintegration.cpp +++ b/src/plugins/platforms/testlite/qglxintegration.cpp @@ -235,8 +235,8 @@ QPlatformWindowFormat QGLXGLContext::reducePlatformWindowFormat(const QPlatformW return retFormat; } -QGLXGLContext::QGLXGLContext(Window window, MyDisplay *xd, QPlatformWindow *platformWindow, const QPlatformWindowFormat &format) - : QPlatformGLContext(platformWindow) +QGLXGLContext::QGLXGLContext(Window window, MyDisplay *xd, const QPlatformWindowFormat &format) + : QPlatformGLContext() , m_xd(xd) , m_drawable((Drawable)window) , m_context(0) @@ -271,7 +271,7 @@ QGLXGLContext::QGLXGLContext(Window window, MyDisplay *xd, QPlatformWindow *plat } QGLXGLContext::QGLXGLContext(MyDisplay *display, Drawable drawable, GLXContext context) - : QPlatformGLContext(0), m_xd(display), m_drawable(drawable), m_context(context) + : QPlatformGLContext(), m_xd(display), m_drawable(drawable), m_context(context) { } diff --git a/src/plugins/platforms/testlite/qglxintegration.h b/src/plugins/platforms/testlite/qglxintegration.h index 432dec5..e17790e 100644 --- a/src/plugins/platforms/testlite/qglxintegration.h +++ b/src/plugins/platforms/testlite/qglxintegration.h @@ -58,7 +58,7 @@ class MyDisplay; class QGLXGLContext : public QPlatformGLContext { public: - QGLXGLContext(Window window, MyDisplay *xd, QPlatformWindow *platformWindow, const QPlatformWindowFormat &format); + QGLXGLContext(Window window, MyDisplay *xd, const QPlatformWindowFormat &format); ~QGLXGLContext(); virtual void makeCurrent(); diff --git a/src/plugins/platforms/testlite/qtestlitewindow.cpp b/src/plugins/platforms/testlite/qtestlitewindow.cpp index 0a6e1ff..b52aae9 100644 --- a/src/plugins/platforms/testlite/qtestlitewindow.cpp +++ b/src/plugins/platforms/testlite/qtestlitewindow.cpp @@ -1021,7 +1021,7 @@ QPlatformGLContext *QTestLiteWindow::glContext() const if (!mGLContext) { QTestLiteWindow *that = const_cast<QTestLiteWindow *>(this); #ifndef QT_NO_OPENGL - that->mGLContext = new QGLXGLContext(x_window, xd, that,widget()->platformWindowFormat()); + that->mGLContext = new QGLXGLContext(x_window, xd,widget()->platformWindowFormat()); #endif } return mGLContext; |