diff options
author | Trond Kjernåsen <trond@trolltech.com> | 2010-01-13 14:53:04 (GMT) |
---|---|---|
committer | Trond Kjernåsen <trond@trolltech.com> | 2010-01-13 14:53:04 (GMT) |
commit | 7bfc32ca6a462b498b9f349454113cd37f64e89f (patch) | |
tree | a224c41e1228f1aa7decda1ed8370e2df66814dc /src/opengl/qgl_x11egl.cpp | |
parent | 59ee1b9d387468a5a80b5c450aa202d1b33e6bd1 (diff) | |
download | Qt-7bfc32ca6a462b498b9f349454113cd37f64e89f.zip Qt-7bfc32ca6a462b498b9f349454113cd37f64e89f.tar.gz Qt-7bfc32ca6a462b498b9f349454113cd37f64e89f.tar.bz2 |
Rework how Qt handles GL extensions.
Qt used to store the GL extensions a particular implementation supported
in a global cache, which was initialized once and never updated.
This could cause problems because different types of context might
support different kinds of extensions (e.g. the difference between
sw and hw contexts). With this patch, the GL extensions are cached
and updated within each QGLContext. It also makes the extension
initialization lazy, which saves application initialization costs for
embedded platforms.
The patch introduces a internal cross platform QGLTemporaryContext
class that is used to create a light-weight GL context without going
via QGLWidget and friends (QWS and WinCE still have QGLWidget fallbacks
for now).
Reviewed-by: Kim
Reviewed-by: Samuel
Diffstat (limited to 'src/opengl/qgl_x11egl.cpp')
-rw-r--r-- | src/opengl/qgl_x11egl.cpp | 194 |
1 files changed, 92 insertions, 102 deletions
diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index 85daf95..572834b 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -55,112 +55,115 @@ QT_BEGIN_NAMESPACE bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig config, const QX11Info &x11Info, bool useArgbVisual); -// -// QGLTempContext is a class for creating a temporary GL context -// (which is needed during QGLWidget initialization to retrieve GL -// extension info). Faster to construct than a full QGLWidget. -// -class QGLTempContext + +/* + QGLTemporaryContext implementation +*/ + +class QGLTemporaryContextPrivate { public: - QGLTempContext(int screen = 0) : - initialized(false), - window(0), - context(0), - surface(0) - { - display = eglGetDisplay(EGLNativeDisplayType(X11->display)); + bool initialized; + Window window; + EGLContext context; + EGLSurface surface; + EGLDisplay display; +}; - if (!eglInitialize(display, NULL, NULL)) { - qWarning("QGLTempContext: Unable to initialize EGL display."); - return; - } +QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) + : d(new QGLTemporaryContextPrivate) +{ + d->initialized = false; + d->window = 0; + d->context = 0; + d->surface = 0; + int screen = 0; + + d->display = eglGetDisplay(EGLNativeDisplayType(X11->display)); - EGLConfig config; - int numConfigs = 0; - EGLint attribs[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + if (!eglInitialize(d->display, NULL, NULL)) { + qWarning("QGLTemporaryContext: Unable to initialize EGL display."); + return; + } + + EGLConfig config; + int numConfigs = 0; + EGLint attribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, #ifdef QT_OPENGL_ES_2 - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, #endif - EGL_NONE - }; + EGL_NONE + }; - eglChooseConfig(display, attribs, &config, 1, &numConfigs); - if (!numConfigs) { - qWarning("QGLTempContext: No EGL configurations available."); - return; - } + eglChooseConfig(d->display, attribs, &config, 1, &numConfigs); + if (!numConfigs) { + qWarning("QGLTemporaryContext: No EGL configurations available."); + return; + } - XVisualInfo visualInfo; - XVisualInfo *vi; - int numVisuals; - EGLint id = 0; - - eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &id); - if (id == 0) { - // EGL_NATIVE_VISUAL_ID is optional and might not be supported - // on some implementations - we'll have to do it the hard way - QX11Info xinfo; - qt_egl_setup_x11_visual(visualInfo, display, config, xinfo, false); - } else { - visualInfo.visualid = id; - } - vi = XGetVisualInfo(X11->display, VisualIDMask, &visualInfo, &numVisuals); - if (!vi || numVisuals < 1) { - qWarning("QGLTempContext: Unable to get X11 visual info id."); - return; - } + XVisualInfo visualInfo; + XVisualInfo *vi; + int numVisuals; + EGLint id = 0; + + eglGetConfigAttrib(d->display, config, EGL_NATIVE_VISUAL_ID, &id); + if (id == 0) { + // EGL_NATIVE_VISUAL_ID is optional and might not be supported + // on some implementations - we'll have to do it the hard way + QX11Info xinfo; + qt_egl_setup_x11_visual(visualInfo, d->display, config, xinfo, false); + } else { + visualInfo.visualid = id; + } + vi = XGetVisualInfo(X11->display, VisualIDMask, &visualInfo, &numVisuals); + if (!vi || numVisuals < 1) { + qWarning("QGLTemporaryContext: Unable to get X11 visual info id."); + return; + } - window = XCreateWindow(X11->display, RootWindow(X11->display, screen), - 0, 0, 1, 1, 0, - vi->depth, InputOutput, vi->visual, - 0, 0); + d->window = XCreateWindow(X11->display, RootWindow(X11->display, screen), + 0, 0, 1, 1, 0, + vi->depth, InputOutput, vi->visual, + 0, 0); - surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType) window, NULL); + d->surface = eglCreateWindowSurface(d->display, config, (EGLNativeWindowType) d->window, NULL); - if (surface == EGL_NO_SURFACE) { - qWarning("QGLTempContext: Error creating EGL surface."); - XFree(vi); - XDestroyWindow(X11->display, window); - return; - } + if (d->surface == EGL_NO_SURFACE) { + qWarning("QGLTemporaryContext: Error creating EGL surface."); + XFree(vi); + XDestroyWindow(X11->display, d->window); + return; + } - EGLint contextAttribs[] = { + EGLint contextAttribs[] = { #ifdef QT_OPENGL_ES_2 - EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_CONTEXT_CLIENT_VERSION, 2, #endif - EGL_NONE - }; - context = eglCreateContext(display, config, 0, contextAttribs); - if (context != EGL_NO_CONTEXT - && eglMakeCurrent(display, surface, surface, context)) - { - initialized = true; - } else { - qWarning("QGLTempContext: Error creating EGL context."); - eglDestroySurface(display, surface); - XDestroyWindow(X11->display, window); - } - XFree(vi); + EGL_NONE + }; + d->context = eglCreateContext(d->display, config, 0, contextAttribs); + if (d->context != EGL_NO_CONTEXT + && eglMakeCurrent(d->display, d->surface, d->surface, d->context)) + { + d->initialized = true; + } else { + qWarning("QGLTemporaryContext: Error creating EGL context."); + eglDestroySurface(d->display, d->surface); + XDestroyWindow(X11->display, d->window); } + XFree(vi); +} - ~QGLTempContext() { - if (initialized) { - eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - eglDestroyContext(display, context); - eglDestroySurface(display, surface); - XDestroyWindow(X11->display, window); - } +QGLTemporaryContext::~QGLTemporaryContext() +{ + if (d->initialized) { + eglMakeCurrent(d->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglDestroyContext(d->display, d->context); + eglDestroySurface(d->display, d->surface); + XDestroyWindow(X11->display, d->window); } - -private: - bool initialized; - Window window; - EGLContext context; - EGLSurface surface; - EGLDisplay display; -}; +} bool QGLFormat::hasOpenGLOverlays() { @@ -547,19 +550,6 @@ void QGLWidget::setColormap(const QGLColormap &) { } -void QGLExtensions::init() -{ - static bool init_done = false; - - if (init_done) - return; - init_done = true; - - // We need a context current to initialize the extensions. - QGLTempContext context; - init_extensions(); -} - // Re-creates the EGL surface if the window ID has changed or if force is true void QGLWidgetPrivate::recreateEglSurface(bool force) { |