void QVGPixmapData::destroyImageAndContext() { if (vgImage != VG_INVALID_HANDLE) { // We need to have a context current to destroy the image. #if !defined(QT_NO_EGL) if (context->isCurrent()) { destroyImages(); } else { // We don't currently have a widget surface active, but we // need a surface to make the context current. So use the // shared pbuffer surface instead. context->makeCurrent(qt_vg_shared_surface()); destroyImages(); context->lazyDoneCurrent(); } #else destroyImages(); #endif } #if !defined(QT_NO_EGL) if (context) { qt_vg_destroy_context(context, QInternal::Pixmap); context = 0; } #endif recreate = true; }
QVGEGLWindowSurfaceDirect::~QVGEGLWindowSurfaceDirect() { destroyPaintEngine(); if (context) { if (windowSurface != EGL_NO_SURFACE) context->destroySurface(windowSurface); qt_vg_destroy_context(context, QInternal::Widget); } }
QVGEGLWindowSurfaceVGImage::~QVGEGLWindowSurfaceVGImage() { destroyPaintEngine(); if (context) { if (backBufferSurface != EGL_NO_SURFACE) { // We need a current context to be able to destroy the image. // We use the shared surface because the native window handle // associated with "windowSurface" may have been destroyed already. context->makeCurrent(qt_vg_shared_surface()); context->destroySurface(backBufferSurface); vgDestroyImage(backBuffer); context->doneCurrent(); } if (windowSurface != EGL_NO_SURFACE) context->destroySurface(windowSurface); qt_vg_destroy_context(context, QInternal::Widget); } }
QEglContext *QVGEGLWindowSurfaceDirect::ensureContext(QWidget *widget) { QSize newSize = windowSurfaceSize(widget); QEglProperties surfaceProps; #if defined(QVG_RECREATE_ON_SIZE_CHANGE) #if !defined(QVG_NO_SINGLE_CONTEXT) if (context && size != newSize) { // The surface size has changed, so we need to recreate it. // We can keep the same context and paint engine. size = newSize; if (isPaintingActive) context->doneCurrent(); context->destroySurface(windowSurface); #if defined(EGL_VG_ALPHA_FORMAT_PRE_BIT) if (isPremultipliedContext(context)) { surfaceProps.setValue (EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_PRE); } else { surfaceProps.removeValue(EGL_VG_ALPHA_FORMAT); } #endif windowSurface = context->createSurface(widget, &surfaceProps); isPaintingActive = false; needToSwap = true; } #else if (context && size != newSize) { // The surface size has changed, so we need to recreate // the EGL context for the widget. We also need to recreate // the surface's paint engine if context sharing is not // enabled because we cannot reuse the existing paint objects // in the new context. qt_vg_destroy_paint_engine(engine); engine = 0; context->destroySurface(windowSurface); qt_vg_destroy_context(context, QInternal::Widget); context = 0; windowSurface = EGL_NO_SURFACE; } #endif #endif if (!context) { // Create a new EGL context and bind it to the widget surface. size = newSize; context = qt_vg_create_context(widget, QInternal::Widget); if (!context) return 0; // We want a direct to window rendering surface if possible. #if defined(QVG_DIRECT_TO_WINDOW) surfaceProps.setValue(EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER); #endif #if defined(EGL_VG_ALPHA_FORMAT_PRE_BIT) if (isPremultipliedContext(context)) { surfaceProps.setValue (EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_PRE); } else { surfaceProps.removeValue(EGL_VG_ALPHA_FORMAT); } #endif EGLSurface surface = context->createSurface(widget, &surfaceProps); if (surface == EGL_NO_SURFACE) { qt_vg_destroy_context(context, QInternal::Widget); context = 0; return 0; } needToSwap = true; #if defined(QVG_DIRECT_TO_WINDOW) // Did we get a direct to window rendering surface? EGLint buffer = 0; if (eglQueryContext(QEgl::display(), context->context(), EGL_RENDER_BUFFER, &buffer) && buffer == EGL_SINGLE_BUFFER) { needToSwap = false; } #endif windowSurface = surface; isPaintingActive = false; } #if !defined(QVG_NO_PRESERVED_SWAP) // Try to force the surface back buffer to preserve its contents. if (needToSwap) { eglGetError(); // Clear error state first. eglSurfaceAttrib(QEgl::display(), windowSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED); if (eglGetError() != EGL_SUCCESS) { qWarning("QVG: could not enable preserved swap"); } } #endif return context; }