void qt_vg_hibernate_pixmaps(QVGSharedContext *shared)
{
    // Artificially increase the reference count to prevent the
    // context from being destroyed until after we have finished
    // the hibernation process.
    ++(shared->refCount);

    // We need a context current to hibernate the VGImage objects.
    shared->context->makeCurrent(qt_vg_shared_surface());

    // Scan all QVGPixmapData objects in the system and hibernate them.
    QVGPixmapData *pd = shared->firstPixmap;
    while (pd != 0) {
        pd->hibernate();
        pd = pd->next;
    }

    // Hibernate any remaining VGImage's in the image pool.
    QVGImagePool::instance()->hibernate();

    // Don't need the current context any more.
    shared->context->lazyDoneCurrent();

    // Decrease the reference count and destroy the context if necessary.
    if (--(shared->refCount) <= 0)
        qt_vg_destroy_shared_context(shared);
}
EGLSurface QVGEGLWindowSurfaceVGImage::mainSurface() const
{
    if (windowSurface != EGL_NO_SURFACE)
        return windowSurface;
    else
        return qt_vg_shared_surface();
}
Example #3
0
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;
}
static void qt_vg_destroy_shared_context(QVGSharedContext *shared)
{
    shared->context->makeCurrent(qt_vg_shared_surface());
    delete shared->engine;
    shared->engine = 0;
    shared->context->doneCurrent();
    if (shared->surface != EGL_NO_SURFACE) {
        eglDestroySurface(QEgl::display(), shared->surface);
        shared->surface = EGL_NO_SURFACE;
    }
    delete shared->context;
    shared->context = 0;
}
QVGSharedContext::~QVGSharedContext()
{
    // Don't accidentally destroy the QEglContext if the reference
    // count falls to zero while deleting the paint engine.
    ++refCount;

    if (context)
        context->makeCurrent(qt_vg_shared_surface());
    delete engine;
    if (context)
        context->doneCurrent();
    if (context && surface != EGL_NO_SURFACE)
        context->destroySurface(surface);
    delete context;
}
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);
    }
}
void qt_vg_destroy_context(QEglContext *context)
{
    QVGSharedContext *shared = sharedContext();
    if (shared->context != context) {
        // This is not the shared context.  Shouldn't happen!
        delete context;
    } else if (--(shared->refCount) <= 0) {
        shared->context->makeCurrent(qt_vg_shared_surface());
        delete shared->engine;
        shared->engine = 0;
        shared->context->doneCurrent();
        if (shared->surface != EGL_NO_SURFACE) {
            eglDestroySurface(shared->context->display(), shared->surface);
            shared->surface = EGL_NO_SURFACE;
        }
        delete shared->context;
        shared->context = 0;
    }
}