Ignore:
Timestamp:
Mar 8, 2010, 12:52:58 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.2 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/opengl/qgl_x11egl.cpp

    r561 r651  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5353QT_BEGIN_NAMESPACE
    5454
     55
     56bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig config,
     57                             const QX11Info &x11Info, bool useArgbVisual);
     58
     59/*
     60    QGLTemporaryContext implementation
     61*/
     62
     63class QGLTemporaryContextPrivate
     64{
     65public:
     66    bool initialized;
     67    Window window;
     68    EGLContext context;
     69    EGLSurface surface;
     70    EGLDisplay display;
     71};
     72
     73QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
     74    : d(new QGLTemporaryContextPrivate)
     75{
     76    d->initialized = false;
     77    d->window = 0;
     78    d->context = 0;
     79    d->surface = 0;
     80    int screen = 0;
     81
     82    d->display = eglGetDisplay(EGLNativeDisplayType(X11->display));
     83
     84    if (!eglInitialize(d->display, NULL, NULL)) {
     85        qWarning("QGLTemporaryContext: Unable to initialize EGL display.");
     86        return;
     87    }
     88
     89    EGLConfig config;
     90    int numConfigs = 0;
     91    EGLint attribs[] = {
     92        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
     93#ifdef QT_OPENGL_ES_2
     94        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
     95#endif
     96        EGL_NONE
     97    };
     98
     99    eglChooseConfig(d->display, attribs, &config, 1, &numConfigs);
     100    if (!numConfigs) {
     101        qWarning("QGLTemporaryContext: No EGL configurations available.");
     102        return;
     103    }
     104
     105    XVisualInfo visualInfo;
     106    XVisualInfo *vi;
     107    int numVisuals;
     108    EGLint id = 0;
     109
     110    eglGetConfigAttrib(d->display, config, EGL_NATIVE_VISUAL_ID, &id);
     111    if (id == 0) {
     112        // EGL_NATIVE_VISUAL_ID is optional and might not be supported
     113        // on some implementations - we'll have to do it the hard way
     114        QX11Info xinfo;
     115        qt_egl_setup_x11_visual(visualInfo, d->display, config, xinfo, false);
     116    } else {
     117        visualInfo.visualid = id;
     118    }
     119    vi = XGetVisualInfo(X11->display, VisualIDMask, &visualInfo, &numVisuals);
     120    if (!vi || numVisuals < 1) {
     121        qWarning("QGLTemporaryContext: Unable to get X11 visual info id.");
     122        return;
     123    }
     124
     125    d->window = XCreateWindow(X11->display, RootWindow(X11->display, screen),
     126                              0, 0, 1, 1, 0,
     127                              vi->depth, InputOutput, vi->visual,
     128                              0, 0);
     129
     130    d->surface = eglCreateWindowSurface(d->display, config, (EGLNativeWindowType) d->window, NULL);
     131
     132    if (d->surface == EGL_NO_SURFACE) {
     133        qWarning("QGLTemporaryContext: Error creating EGL surface.");
     134        XFree(vi);
     135        XDestroyWindow(X11->display, d->window);
     136        return;
     137    }
     138
     139    EGLint contextAttribs[] = {
     140#ifdef QT_OPENGL_ES_2
     141        EGL_CONTEXT_CLIENT_VERSION, 2,
     142#endif
     143        EGL_NONE
     144    };
     145    d->context = eglCreateContext(d->display, config, 0, contextAttribs);
     146    if (d->context != EGL_NO_CONTEXT
     147        && eglMakeCurrent(d->display, d->surface, d->surface, d->context))
     148    {
     149        d->initialized = true;
     150    } else {
     151        qWarning("QGLTemporaryContext: Error creating EGL context.");
     152        eglDestroySurface(d->display, d->surface);
     153        XDestroyWindow(X11->display, d->window);
     154    }
     155    XFree(vi);
     156}
     157
     158QGLTemporaryContext::~QGLTemporaryContext()
     159{
     160    if (d->initialized) {
     161        eglMakeCurrent(d->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
     162        eglDestroyContext(d->display, d->context);
     163        eglDestroySurface(d->display, d->surface);
     164        XDestroyWindow(X11->display, d->window);
     165    }
     166}
     167
    55168bool QGLFormat::hasOpenGLOverlays()
    56169{
     
    240353    // If EGL does not know the visual ID, so try to select an appropriate one ourselves, first
    241354    // using XRender if we're supposed to have an alpha, then falling back to XGetVisualInfo
    242          
     355
    243356#if !defined(QT_NO_XRENDER)
    244357    if (vi.visualid == 0 && useArgbVisual) {
     
    438551}
    439552
    440 void QGLExtensions::init()
    441 {
    442     static bool init_done = false;
    443 
    444     if (init_done)
    445         return;
    446     init_done = true;
    447 
    448     // We need a context current to initialize the extensions.
    449     QGLWidget tmpWidget;
    450     tmpWidget.makeCurrent();
    451 
    452     init_extensions();
    453 
    454     tmpWidget.doneCurrent();
    455 }
    456 
    457553// Re-creates the EGL surface if the window ID has changed or if force is true
    458554void QGLWidgetPrivate::recreateEglSurface(bool force)
Note: See TracChangeset for help on using the changeset viewer.