From f3d15516572394b6bcd44a89dd66516fa4eba56e Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Fri, 25 Sep 2009 10:21:23 +1000 Subject: Remove the storage of the EGLSurface from QEglContext Reviewed-by: Sarah Smith --- src/gui/egl/qegl.cpp | 53 ------------------------------------- src/gui/egl/qegl_p.h | 11 +------- src/gui/egl/qegl_qws.cpp | 4 +-- src/gui/egl/qegl_symbian.cpp | 11 ++++---- src/gui/egl/qegl_wince.cpp | 8 +++--- src/gui/egl/qegl_x11.cpp | 8 +++--- src/opengl/qgl_qws.cpp | 19 ++++++------- src/opengl/qgl_wince.cpp | 4 +-- src/opengl/qgl_x11egl.cpp | 13 ++++++--- src/opengl/qglpixelbuffer_egl.cpp | 5 ++-- src/openvg/qwindowsurface_vgegl.cpp | 12 ++++----- 11 files changed, 42 insertions(+), 106 deletions(-) diff --git a/src/gui/egl/qegl.cpp b/src/gui/egl/qegl.cpp index a405bbb..f06c153 100644 --- a/src/gui/egl/qegl.cpp +++ b/src/gui/egl/qegl.cpp @@ -58,7 +58,6 @@ QEglContext::QEglContext() : apiType(QEgl::OpenGL) , dpy(EGL_NO_DISPLAY) , ctx(EGL_NO_CONTEXT) - , surf(EGL_NO_SURFACE) , cfg(0) , currentSurface(EGL_NO_SURFACE) , share(false) @@ -198,30 +197,6 @@ bool QEglContext::createContext(QEglContext *shareContext) return true; } -// Recreate the surface for a paint device because the native id has changed. -bool QEglContext::recreateSurface(QPaintDevice *device) -{ - // Bail out if the surface has not been created for the first time yet. - if (surf == EGL_NO_SURFACE) - return true; - - // Destroy the old surface. - eglDestroySurface(dpy, surf); - surf = EGL_NO_SURFACE; - - // Create a new one. - return createSurface(device); -} - -// Destroy the EGL surface object. -void QEglContext::destroySurface() -{ - if (surf != EGL_NO_SURFACE) { - eglDestroySurface(dpy, surf); - surf = EGL_NO_SURFACE; - } -} - // Destroy an EGL surface object. If it was current on this context // then call doneCurrent() for it first. void QEglContext::destroySurface(EGLSurface surface) @@ -230,8 +205,6 @@ void QEglContext::destroySurface(EGLSurface surface) if (surface == currentSurface) doneCurrent(); eglDestroySurface(dpy, surface); - if (surf == surface) - surf = EGL_NO_SURFACE; } } @@ -242,16 +215,10 @@ void QEglContext::destroy() eglDestroyContext(dpy, ctx); dpy = EGL_NO_DISPLAY; ctx = EGL_NO_CONTEXT; - surf = EGL_NO_SURFACE; cfg = 0; share = false; } -bool QEglContext::makeCurrent() -{ - return makeCurrent(surf); -} - bool QEglContext::makeCurrent(EGLSurface surface) { if (ctx == EGL_NO_CONTEXT) { @@ -316,17 +283,6 @@ bool QEglContext::lazyDoneCurrent() return true; } -bool QEglContext::swapBuffers() -{ - if(ctx == EGL_NO_CONTEXT) - return false; - - bool ok = eglSwapBuffers(dpy, surf); - if (!ok) - qWarning() << "QEglContext::swapBuffers():" << errorString(eglGetError()); - return ok; -} - bool QEglContext::swapBuffers(EGLSurface surface) { if(ctx == EGL_NO_CONTEXT) @@ -368,15 +324,6 @@ void QEglContext::waitClient() #endif } -// Query the actual size of the EGL surface. -QSize QEglContext::surfaceSize() const -{ - int w, h; - eglQuerySurface(dpy, surf, EGL_WIDTH, &w); - eglQuerySurface(dpy, surf, EGL_HEIGHT, &h); - return QSize(w, h); -} - // Query the value of a configuration attribute. bool QEglContext::configAttrib(int name, EGLint *value) const { diff --git a/src/gui/egl/qegl_p.h b/src/gui/egl/qegl_p.h index 3903cd0..afec29b 100644 --- a/src/gui/egl/qegl_p.h +++ b/src/gui/egl/qegl_p.h @@ -89,25 +89,19 @@ public: bool openDisplay(QPaintDevice *device); bool chooseConfig(const QEglProperties& properties, QEgl::PixelFormatMatch match = QEgl::ExactPixelFormat); bool createContext(QEglContext *shareContext = 0); - bool createSurface(QPaintDevice *device, const QEglProperties *properties = 0); - bool recreateSurface(QPaintDevice *device); - void destroySurface(); + EGLSurface createSurface(QPaintDevice *device, const QEglProperties *properties = 0); void destroySurface(EGLSurface surface); void destroy(); - bool makeCurrent(); bool makeCurrent(EGLSurface surface); bool doneCurrent(); bool lazyDoneCurrent(); - bool swapBuffers(); bool swapBuffers(EGLSurface surface); void waitNative(); void waitClient(); - QSize surfaceSize() const; - bool configAttrib(int name, EGLint *value) const; static void clearError() { eglGetError(); } @@ -116,8 +110,6 @@ public: EGLDisplay display() const { return dpy; } EGLContext context() const { return ctx; } - EGLSurface surface() const { return surf; } - void setSurface(EGLSurface surface) { surf = surface; } EGLConfig config() const { return cfg; } QEglProperties configProperties(EGLConfig cfg = 0) const; @@ -133,7 +125,6 @@ private: QEgl::API apiType; EGLDisplay dpy; EGLContext ctx; - EGLSurface surf; EGLConfig cfg; EGLSurface currentSurface; bool share; diff --git a/src/gui/egl/qegl_qws.cpp b/src/gui/egl/qegl_qws.cpp index 2754589..590b666 100644 --- a/src/gui/egl/qegl_qws.cpp +++ b/src/gui/egl/qegl_qws.cpp @@ -57,11 +57,11 @@ QT_BEGIN_NAMESPACE // We don't have QGLScreen to create EGL surfaces for us, // so surface creation needs to be done in QtOpenGL or // QtOpenVG for Qt/Embedded. -bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties) +EGLSurface QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties) { Q_UNUSED(device); Q_UNUSED(properties); - return false; + return EGL_NO_SURFACE; } EGLDisplay QEglContext::getDisplay(QPaintDevice *device) diff --git a/src/gui/egl/qegl_symbian.cpp b/src/gui/egl/qegl_symbian.cpp index fa0b5cb..2101f0b 100644 --- a/src/gui/egl/qegl_symbian.cpp +++ b/src/gui/egl/qegl_symbian.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE -bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties) +EGLSurface QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties) { // Create the native drawable for the paint device. int devType = device->devType(); @@ -67,7 +67,7 @@ bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *prop } if (!ok) { qWarning("QEglContext::createSurface(): Cannot create the native EGL drawable"); - return false; + return EGL_NO_SURFACE; } // Create the EGL surface to draw into, based on the native drawable. @@ -76,15 +76,14 @@ bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *prop props = properties->properties(); else props = 0; + EGLSurface surf; if (devType == QInternal::Widget) surf = eglCreateWindowSurface(dpy, cfg, windowDrawable, 0); else surf = eglCreatePixmapSurface(dpy, cfg, pixmapDrawable, 0); - if (surf == EGL_NO_SURFACE) { + if (surf == EGL_NO_SURFACE) qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError()); - return false; - } - return true; + return surf; } EGLDisplay QEglContext::getDisplay(QPaintDevice *device) diff --git a/src/gui/egl/qegl_wince.cpp b/src/gui/egl/qegl_wince.cpp index e07d748..bf07f85 100644 --- a/src/gui/egl/qegl_wince.cpp +++ b/src/gui/egl/qegl_wince.cpp @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE -bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties) +EGLSurface QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties) { // Create the native drawable for the paint device. int devType = device->devType(); @@ -67,7 +67,7 @@ bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *prop } if (!ok) { qWarning("QEglContext::createSurface(): Cannot create the native EGL drawable"); - return false; + return EGL_NO_SURFACE; } // Create the EGL surface to draw into, based on the native drawable. @@ -76,15 +76,15 @@ bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *prop props = properties->properties(); else props = 0; + EGLSurface surf; if (devType == QInternal::Widget) surf = eglCreateWindowSurface(dpy, cfg, windowDrawable, props); else surf = eglCreatePixmapSurface(dpy, cfg, pixmapDrawable, props); if (surf == EGL_NO_SURFACE) { qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError()); - return false; } - return true; + return surf; } EGLDisplay QEglContext::getDisplay(QPaintDevice *device) diff --git a/src/gui/egl/qegl_x11.cpp b/src/gui/egl/qegl_x11.cpp index 5f34f8e..9d556a8 100644 --- a/src/gui/egl/qegl_x11.cpp +++ b/src/gui/egl/qegl_x11.cpp @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE -bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties) +EGLSurface QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties) { // Create the native drawable for the paint device. int devType = device->devType(); @@ -72,7 +72,7 @@ bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *prop } if (!ok) { qWarning("QEglContext::createSurface(): Cannot create the native EGL drawable"); - return false; + return EGL_NO_SURFACE; } // Create the EGL surface to draw into, based on the native drawable. @@ -81,6 +81,7 @@ bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *prop props = properties->properties(); else props = 0; + EGLSurface surf; if (devType == QInternal::Widget) surf = eglCreateWindowSurface(dpy, cfg, windowDrawable, props); else @@ -88,9 +89,8 @@ bool QEglContext::createSurface(QPaintDevice *device, const QEglProperties *prop if (surf == EGL_NO_SURFACE) { qWarning() << "QEglContext::createSurface(): Unable to create EGL surface:" << errorString(eglGetError()); - return false; } - return true; + return surf; } EGLDisplay QEglContext::getDisplay(QPaintDevice *device) diff --git a/src/opengl/qgl_qws.cpp b/src/opengl/qgl_qws.cpp index b8a8777..d158e44 100644 --- a/src/opengl/qgl_qws.cpp +++ b/src/opengl/qgl_qws.cpp @@ -117,17 +117,17 @@ void qt_egl_add_platform_config(QEglProperties& props, QPaintDevice *device) props.setPixelFormat(glScreen->pixelFormat()); } -static bool qt_egl_create_surface +static EGLSurface qt_egl_create_surface (QEglContext *context, QPaintDevice *device, const QEglProperties *properties = 0) { // Get the screen surface functions, which are used to create native ids. QGLScreen *glScreen = glScreenForDevice(device); if (!glScreen) - return false; + return EGL_NO_SURFACE; QGLScreenSurfaceFunctions *funcs = glScreen->surfaceFunctions(); if (!funcs) - return false; + return EGL_NO_SURFACE; // Create the native drawable for the paint device. int devType = device->devType(); @@ -143,7 +143,7 @@ static bool qt_egl_create_surface } if (!ok) { qWarning("QEglContext::createSurface(): Cannot create the native EGL drawable"); - return false; + return EGL_NO_SURFACE; } // Create the EGL surface to draw into, based on the native drawable. @@ -160,12 +160,9 @@ static bool qt_egl_create_surface surf = eglCreatePixmapSurface (context->display(), context->config(), pixmapDrawable, props); } - if (surf == EGL_NO_SURFACE) { + if (surf == EGL_NO_SURFACE) qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError()); - return false; - } - context->setSurface(surf); - return true; + return surf; } bool QGLContext::chooseContext(const QGLContext* shareContext) @@ -223,12 +220,12 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) // Create the EGL surface to draw into. We cannot use // QEglContext::createSurface() because it does not have // access to the QGLScreen. - if (!qt_egl_create_surface(d->eglContext, device())) { + d->eglSurface = qt_egl_create_surface(d->eglContext, device()); + if (d->eglSurface == EGL_NO_SURFACE) { delete d->eglContext; d->eglContext = 0; return false; } - d->eglSurface = d->eglContext->surface(); return true; } diff --git a/src/opengl/qgl_wince.cpp b/src/opengl/qgl_wince.cpp index f951ea0..dbb5c98 100644 --- a/src/opengl/qgl_wince.cpp +++ b/src/opengl/qgl_wince.cpp @@ -178,12 +178,12 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) #endif // Create the EGL surface to draw into. - if (!d->eglContext->createSurface(device())) { + d->eglSurface = d->eglContext->createSurface(device()); + if (d->eglSurface == EGL_NO_SURFACE) { delete d->eglContext; d->eglContext = 0; return false; } - d->eglSurface = d->eglContext->surface(); return true; diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index c054860..2214775 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -363,12 +363,12 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, // Create the EGL surface to draw into. QGLContextPrivate *ctxpriv = d->glcx->d_func(); - if (!ctxpriv->eglContext->createSurface(this)) { + ctxpriv->eglSurface = ctxpriv->eglContext->createSurface(this); + if (ctxpriv->eglSurface == EGL_NO_SURFACE) { delete ctxpriv->eglContext; ctxpriv->eglContext = 0; return; } - ctxpriv->eglSurface = ctxpriv->eglContext->surface(); d->eglSurfaceWindowId = w; // Remember the window id we created the surface for @@ -435,9 +435,14 @@ void QGLWidgetPrivate::recreateEglSurface(bool force) if ( force || (currentId != eglSurfaceWindowId) ) { // The window id has changed so we need to re-create the EGL surface - if (!glcx->d_func()->eglContext->recreateSurface(q)) + QEglContext *ctx = glcx->d_func()->eglContext; + EGLSurface surface = glcx->d_func()->eglSurface; + if (surface != EGL_NO_SURFACE) + ctx->destroySurface(surface); // Will force doneCurrent() if nec. + surface = ctx->createSurface(q); + if (surface == EGL_NO_SURFACE) qWarning("Error creating EGL window surface: 0x%x", eglGetError()); - glcx->d_func()->eglSurface = glcx->d_func()->eglContext->surface(); + glcx->d_func()->eglSurface = surface; eglSurfaceWindowId = currentId; } diff --git a/src/opengl/qglpixelbuffer_egl.cpp b/src/opengl/qglpixelbuffer_egl.cpp index e331de5..4cba1bb 100644 --- a/src/opengl/qglpixelbuffer_egl.cpp +++ b/src/opengl/qglpixelbuffer_egl.cpp @@ -135,7 +135,6 @@ bool QGLPixelBufferPrivate::init(const QSize &size, const QGLFormat &f, QGLWidge qWarning() << "QGLPixelBufferPrivate::init(): Unable to create EGL pbuffer surface:" << QEglContext::errorString(eglGetError()); return false; } - ctx->setSurface(pbuf); // Create a new context for the configuration. QEglContext *shareContext = 0; @@ -163,7 +162,7 @@ bool QGLPixelBuffer::bindToDynamicTexture(GLuint texture_id) if (d->invalid || d->textureFormat == EGL_NONE || !d->ctx) return false; glBindTexture(GL_TEXTURE_2D, texture_id); - return eglBindTexImage(d->ctx->display(), d->ctx->surface(), EGL_BACK_BUFFER); + return eglBindTexImage(d->ctx->display(), d->pbuf, EGL_BACK_BUFFER); #else Q_UNUSED(texture_id); return false; @@ -176,7 +175,7 @@ void QGLPixelBuffer::releaseFromDynamicTexture() Q_D(QGLPixelBuffer); if (d->invalid || d->textureFormat == EGL_NONE || !d->ctx) return; - eglReleaseTexImage(d->ctx->display(), d->ctx->surface(), EGL_BACK_BUFFER); + eglReleaseTexImage(d->ctx->display(), d->pbuf, EGL_BACK_BUFFER); #endif } diff --git a/src/openvg/qwindowsurface_vgegl.cpp b/src/openvg/qwindowsurface_vgegl.cpp index cb3f7fc..3ae911f 100644 --- a/src/openvg/qwindowsurface_vgegl.cpp +++ b/src/openvg/qwindowsurface_vgegl.cpp @@ -586,9 +586,7 @@ QEglContext *QVGEGLWindowSurfaceDirect::ensureContext(QWidget *widget) surfaceProps.removeValue(EGL_VG_ALPHA_FORMAT); } #endif - context->createSurface(widget, &surfaceProps); - windowSurface = context->surface(); - context->setSurface(EGL_NO_SURFACE); + windowSurface = context->createSurface(widget, &surfaceProps); isPaintingActive = false; } #else @@ -625,7 +623,8 @@ QEglContext *QVGEGLWindowSurfaceDirect::ensureContext(QWidget *widget) surfaceProps.removeValue(EGL_VG_ALPHA_FORMAT); } #endif - if (!context->createSurface(widget, &surfaceProps)) { + EGLSurface surface = context->createSurface(widget, &surfaceProps); + if (surface == EGL_NO_SURFACE) { qt_vg_destroy_context(context); context = 0; return 0; @@ -644,15 +643,14 @@ QEglContext *QVGEGLWindowSurfaceDirect::ensureContext(QWidget *widget) // Try to force the surface back buffer to preserve its contents. if (needToSwap) { eglGetError(); // Clear error state first. - eglSurfaceAttrib(context->display(), context->surface(), + eglSurfaceAttrib(context->display(), surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED); if (eglGetError() != EGL_SUCCESS) { qWarning("QVG: could not enable preserved swap"); } } #endif - windowSurface = context->surface(); - context->setSurface(EGL_NO_SURFACE); + windowSurface = surface; isPaintingActive = false; } return context; -- cgit v0.12