Changeset 846 for trunk/src/gui/egl


Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/egl/egl.pri

    r769 r846  
    44        HEADERS += \
    55            egl/qegl_p.h \
     6            egl/qeglcontext_p.h \
    67            egl/qeglproperties_p.h
    78
  • trunk/src/gui/egl/qegl.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4545#include <QtCore/qatomic.h>
    4646#include <QtCore/qdebug.h>
     47
    4748#include "qegl_p.h"
     49#include "qeglcontext_p.h"
     50
    4851
    4952QT_BEGIN_NAMESPACE
     
    6265    static void deref() {
    6366        if (!contexts.deref()) {
    64             eglTerminate(QEglContext::display());
     67            eglTerminate(QEgl::display());
    6568            displayOpen = 0;
    6669        }
     
    8487static QEglContext * volatile currentVGContext = 0;
    8588
    86 EGLDisplay QEglContext::dpy = EGL_NO_DISPLAY;
    87 
    8889QEglContext::QEglContext()
    8990    : apiType(QEgl::OpenGL)
    9091    , ctx(EGL_NO_CONTEXT)
    91     , cfg(0)
     92    , cfg(QEGL_NO_CONFIG)
    9293    , currentSurface(EGL_NO_SURFACE)
    9394    , current(false)
     
    119120}
    120121
     122EGLConfig QEgl::defaultConfig(int devType, API api, ConfigOptions options)
     123{
     124    if ( (devType != QInternal::Pixmap) && ((options & Renderable) == 0))
     125        qWarning("QEgl::defaultConfig() - Only configs for pixmaps make sense to be read-only!");
     126
     127    EGLConfig* targetConfig = 0;
     128
     129    static EGLConfig defaultVGConfigs[] = {
     130        QEGL_NO_CONFIG, // 0    Window  Renderable  Translucent
     131        QEGL_NO_CONFIG, // 1    Window  Renderable  Opaque
     132        QEGL_NO_CONFIG, // 2    Pixmap  Renderable  Translucent
     133        QEGL_NO_CONFIG, // 3    Pixmap  Renderable  Opaque
     134        QEGL_NO_CONFIG, // 4    Pixmap  ReadOnly    Translucent
     135        QEGL_NO_CONFIG  // 5    Pixmap  ReadOnly    Opaque
     136    };
     137    if (api == OpenVG) {
     138        if (devType == QInternal::Widget) {
     139            if (options & Translucent)
     140                targetConfig = &(defaultVGConfigs[0]);
     141            else
     142                targetConfig = &(defaultVGConfigs[1]);
     143        } else if (devType == QInternal::Pixmap) {
     144            if (options & Renderable) {
     145                if (options & Translucent)
     146                    targetConfig = &(defaultVGConfigs[2]);
     147                else // Opaque
     148                    targetConfig = &(defaultVGConfigs[3]);
     149            } else { // Read-only
     150                if (options & Translucent)
     151                    targetConfig = &(defaultVGConfigs[4]);
     152                else // Opaque
     153                    targetConfig = &(defaultVGConfigs[5]);
     154            }
     155        }
     156    }
     157
     158
     159    static EGLConfig defaultGLConfigs[] = {
     160        QEGL_NO_CONFIG, // 0    Window  Renderable  Translucent
     161        QEGL_NO_CONFIG, // 1    Window  Renderable  Opaque
     162        QEGL_NO_CONFIG, // 2    PBuffer Renderable  Translucent
     163        QEGL_NO_CONFIG, // 3    PBuffer Renderable  Opaque
     164        QEGL_NO_CONFIG, // 4    Pixmap  Renderable  Translucent
     165        QEGL_NO_CONFIG, // 5    Pixmap  Renderable  Opaque
     166        QEGL_NO_CONFIG, // 6    Pixmap  ReadOnly    Translucent
     167        QEGL_NO_CONFIG  // 7    Pixmap  ReadOnly    Opaque
     168    };
     169    if (api == OpenGL) {
     170        if (devType == QInternal::Widget) {
     171            if (options & Translucent)
     172                targetConfig = &(defaultGLConfigs[0]);
     173            else // Opaque
     174                targetConfig = &(defaultGLConfigs[1]);
     175        } else if (devType == QInternal::Pbuffer) {
     176            if (options & Translucent)
     177                targetConfig = &(defaultGLConfigs[2]);
     178            else // Opaque
     179                targetConfig = &(defaultGLConfigs[3]);
     180        } else if (devType == QInternal::Pixmap) {
     181            if (options & Renderable) {
     182                if (options & Translucent)
     183                    targetConfig = &(defaultGLConfigs[4]);
     184                else // Opaque
     185                    targetConfig = &(defaultGLConfigs[5]);
     186            } else { // ReadOnly
     187                if (options & Translucent)
     188                    targetConfig = &(defaultGLConfigs[6]);
     189                else // Opaque
     190                    targetConfig = &(defaultGLConfigs[7]);
     191            }
     192        }
     193    }
     194
     195    if (!targetConfig) {
     196        qWarning("QEgl::defaultConfig() - No default config for device/api/options combo");
     197        return QEGL_NO_CONFIG;
     198    }
     199    if (*targetConfig != QEGL_NO_CONFIG)
     200        return *targetConfig;
     201
     202
     203    // We haven't found an EGL config for the target config yet, so do it now:
     204
     205
     206    // Allow overriding from an environment variable:
     207    QByteArray configId;
     208    if (api == OpenVG)
     209        configId = qgetenv("QT_VG_EGL_CONFIG");
     210    else
     211        configId = qgetenv("QT_GL_EGL_CONFIG");
     212    if (!configId.isEmpty()) {
     213        // Overridden, so get the EGLConfig for the specified config ID:
     214        EGLint properties[] = {
     215            EGL_CONFIG_ID, (EGLint)configId.toInt(),
     216            EGL_NONE
     217        };
     218        EGLint configCount = 0;
     219        eglChooseConfig(display(), properties, targetConfig, 1, &configCount);
     220        if (configCount > 0)
     221            return *targetConfig;
     222        qWarning() << "QEgl::defaultConfig() -" << configId << "appears to be invalid";
     223    }
     224
     225    QEglProperties configAttribs;
     226    configAttribs.setRenderableType(api);
     227
     228    EGLint surfaceType;
     229    switch (devType) {
     230        case QInternal::Widget:
     231            surfaceType = EGL_WINDOW_BIT;
     232            break;
     233        case QInternal::Pixmap:
     234            surfaceType = EGL_PIXMAP_BIT;
     235            break;
     236        case QInternal::Pbuffer:
     237            surfaceType = EGL_PBUFFER_BIT;
     238            break;
     239        default:
     240            qWarning("QEgl::defaultConfig() - Can't create EGL surface for %d device type", devType);
     241            return QEGL_NO_CONFIG;
     242    };
     243#ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT
     244    // For OpenVG, we try to create a surface using a pre-multiplied format if
     245    // the surface needs to have an alpha channel:
     246    if (api == OpenVG && (options & Translucent))
     247        surfaceType |= EGL_VG_ALPHA_FORMAT_PRE_BIT;
     248#endif
     249    configAttribs.setValue(EGL_SURFACE_TYPE, surfaceType);
     250
     251#ifdef EGL_BIND_TO_TEXTURE_RGBA
     252    if (devType == QInternal::Pixmap || devType == QInternal::Pbuffer) {
     253        if (options & Translucent)
     254            configAttribs.setValue(EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE);
     255        else
     256            configAttribs.setValue(EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE);
     257    }
     258#endif
     259
     260    // Add paint engine requirements
     261    if (api == OpenVG) {
     262#if !defined(QVG_SCISSOR_CLIP) && defined(EGL_ALPHA_MASK_SIZE)
     263        configAttribs.setValue(EGL_ALPHA_MASK_SIZE, 1);
     264#endif
     265    } else {
     266        // Both OpenGL paint engines need to have stencil and sample buffers
     267        configAttribs.setValue(EGL_STENCIL_SIZE, 1);
     268        configAttribs.setValue(EGL_SAMPLE_BUFFERS, 1);
     269#ifndef QT_OPENGL_ES_2
     270        // Additionally, the GL1 engine likes to have a depth buffer for clipping
     271        configAttribs.setValue(EGL_DEPTH_SIZE, 1);
     272#endif
     273    }
     274
     275    if (options & Translucent)
     276        configAttribs.setValue(EGL_ALPHA_SIZE, 1);
     277
     278    *targetConfig = chooseConfig(&configAttribs, QEgl::BestPixelFormat);
     279    return *targetConfig;
     280}
     281
     282
    121283// Choose a configuration that matches "properties".
    122 bool QEglContext::chooseConfig
    123         (const QEglProperties& properties, QEgl::PixelFormatMatch match)
    124 {
    125     QEglProperties props(properties);
     284EGLConfig QEgl::chooseConfig(const QEglProperties* properties, QEgl::PixelFormatMatch match)
     285{
     286    QEglProperties props(*properties);
     287    EGLConfig cfg = QEGL_NO_CONFIG;
    126288    do {
    127289        // Get the number of matching configurations for this set of properties.
    128290        EGLint matching = 0;
    129         if (!eglChooseConfig(display(), props.properties(), 0, 0, &matching) || !matching)
     291        EGLDisplay dpy = QEgl::display();
     292        if (!eglChooseConfig(dpy, props.properties(), 0, 0, &matching) || !matching)
    130293            continue;
    131294
     
    136299            if (matching < 1)
    137300                continue;
    138             return true;
     301            return cfg;
    139302        }
    140303
     
    157320                cfg = configs[index];
    158321                delete [] configs;
    159                 return true;
     322                return cfg;
    160323            }
    161324        }
     
    174337        qWarning() << "Requested:" << props.toString();
    175338        qWarning() << "Available:";
    176         dumpAllConfigs();
    177     }
    178     return false;
    179 }
     339        QEgl::dumpAllConfigs();
     340    }
     341    return QEGL_NO_CONFIG;
     342}
     343
     344bool QEglContext::chooseConfig(const QEglProperties& properties, QEgl::PixelFormatMatch match)
     345{
     346    cfg = QEgl::chooseConfig(&properties, match);
     347    return cfg != QEGL_NO_CONFIG;
     348}
     349
     350EGLSurface QEglContext::createSurface(QPaintDevice* device, const QEglProperties *properties)
     351{
     352    return QEgl::createSurface(device, cfg, properties);
     353}
     354
    180355
    181356// Create the EGLContext.
     
    183358{
    184359    // We need to select the correct API before calling eglCreateContext().
     360#ifdef QT_OPENGL_ES
    185361#ifdef EGL_OPENGL_ES_API
    186362    if (apiType == QEgl::OpenGL)
    187363        eglBindAPI(EGL_OPENGL_ES_API);
    188364#endif
     365#else
     366#ifdef EGL_OPENGL_API
     367    if (apiType == QEgl::OpenGL)
     368        eglBindAPI(EGL_OPENGL_API);
     369#endif
     370#endif //defined(QT_OPENGL_ES)
    189371#ifdef EGL_OPENVG_API
    190372    if (apiType == QEgl::OpenVG)
     
    196378    if (properties)
    197379        contextProps = *properties;
    198 #if defined(QT_OPENGL_ES_2)
     380#ifdef QT_OPENGL_ES_2
    199381    if (apiType == QEgl::OpenGL)
    200382        contextProps.setValue(EGL_CONTEXT_CLIENT_VERSION, 2);
     
    204386        shareContext = 0;
    205387    if (shareContext) {
    206         ctx = eglCreateContext(display(), cfg, shareContext->ctx, contextProps.properties());
     388        ctx = eglCreateContext(QEgl::display(), cfg, shareContext->ctx, contextProps.properties());
    207389        if (ctx == EGL_NO_CONTEXT) {
    208             qWarning() << "QEglContext::createContext(): Could not share context:" << errorString(eglGetError());
     390            qWarning() << "QEglContext::createContext(): Could not share context:" << QEgl::errorString();
    209391            shareContext = 0;
    210392        } else {
     
    215397        ctx = eglCreateContext(display(), cfg, 0, contextProps.properties());
    216398        if (ctx == EGL_NO_CONTEXT) {
    217             qWarning() << "QEglContext::createContext(): Unable to create EGL context:" << errorString(eglGetError());
     399            qWarning() << "QEglContext::createContext(): Unable to create EGL context:" << QEgl::errorString();
    218400            return false;
    219401        }
     
    246428    if (ctx == EGL_NO_CONTEXT) {
    247429        qWarning() << "QEglContext::makeCurrent(): Cannot make invalid context current";
     430        return false;
     431    }
     432
     433    if (surface == EGL_NO_SURFACE) {
     434        qWarning() << "QEglContext::makeCurrent(): Cannot make invalid surface current";
    248435        return false;
    249436    }
     
    272459#endif
    273460
    274     bool ok = eglMakeCurrent(display(), surface, surface, ctx);
     461    bool ok = eglMakeCurrent(QEgl::display(), surface, surface, ctx);
    275462    if (!ok)
    276         qWarning() << "QEglContext::makeCurrent():" << errorString(eglGetError());
     463        qWarning() << "QEglContext::makeCurrent(" << surface << "):" << QEgl::errorString();
    277464    return ok;
    278465}
     
    301488#endif
    302489
    303     bool ok = eglMakeCurrent(display(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
     490    bool ok = eglMakeCurrent(QEgl::display(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    304491    if (!ok)
    305         qWarning() << "QEglContext::doneCurrent():" << errorString(eglGetError());
     492        qWarning() << "QEglContext::doneCurrent():" << QEgl::errorString();
    306493    return ok;
    307494}
     
    323510        return false;
    324511
    325     bool ok = eglSwapBuffers(display(), surface);
     512    bool ok = eglSwapBuffers(QEgl::display(), surface);
    326513    if (!ok)
    327         qWarning() << "QEglContext::swapBuffers():" << errorString(eglGetError());
     514        qWarning() << "QEglContext::swapBuffers():" << QEgl::errorString();
    328515    return ok;
    329516}
    330517
    331 // Wait for native rendering operations to complete before starting
    332 // to use OpenGL/OpenVG operations.
    333 void QEglContext::waitNative()
    334 {
    335 #ifdef EGL_CORE_NATIVE_ENGINE
    336     eglWaitNative(EGL_CORE_NATIVE_ENGINE);
    337 #endif
    338 }
    339 
    340 // Wait for client OpenGL/OpenVG operations to complete before
    341 // using native rendering operations.
    342 void QEglContext::waitClient()
    343 {
    344 #ifdef EGL_OPENGL_ES_API
    345     if (apiType == QEgl::OpenGL) {
    346         eglBindAPI(EGL_OPENGL_ES_API);
    347         eglWaitClient();
    348     }
    349 #else
    350     if (apiType == QEgl::OpenGL)
    351         eglWaitGL();
    352 #endif
    353 #ifdef EGL_OPENVG_API
    354     if (apiType == QEgl::OpenVG) {
    355         eglBindAPI(EGL_OPENVG_API);
    356         eglWaitClient();
    357     }
    358 #endif
    359 }
    360 
    361 // Query the value of a configuration attribute.
    362 bool QEglContext::configAttrib(int name, EGLint *value) const
    363 {
    364     return eglGetConfigAttrib(display(), cfg, name, value);
    365 }
    366 
    367 void QEglContext::clearError()
    368 {
    369     eglGetError();
    370 }
    371 
    372 EGLint QEglContext::error()
    373 {
    374     return eglGetError();
    375 }
    376 
    377 // Retrieve all of the properties on "cfg".  If zero, return
    378 // the context's configuration.
    379 QEglProperties QEglContext::configProperties(EGLConfig cfg) const
    380 {
    381     if (!cfg)
    382         cfg = config();
    383     QEglProperties props;
    384     for (int name = 0x3020; name <= 0x304F; ++name) {
    385         EGLint value;
    386         if (name != EGL_NONE && eglGetConfigAttrib(display(), cfg, name, &value))
    387             props.setValue(name, value);
    388     }
    389     eglGetError();  // Clear the error state.
    390     return props;
    391 }
    392 
    393 EGLDisplay QEglContext::display()
    394 {
     518bool QEglContext::swapBuffersRegion2NOK(EGLSurface surface, const QRegion *region) {
     519    QVector<QRect> qrects = region->rects();
     520    EGLint *gl_rects;
     521    uint count;
     522    uint i;
     523
     524    count = qrects.size();
     525    QVarLengthArray <EGLint> arr(4 * count);
     526    gl_rects = arr.data();
     527    for (i = 0; i < count; i++) {
     528      QRect qrect = qrects[i];
     529
     530      gl_rects[4 * i + 0] = qrect.x();
     531      gl_rects[4 * i + 1] = qrect.y();
     532      gl_rects[4 * i + 2] = qrect.width();
     533      gl_rects[4 * i + 3] = qrect.height();
     534    }
     535
     536    bool ok = QEgl::eglSwapBuffersRegion2NOK(QEgl::display(), surface, count, gl_rects);
     537
     538    if (!ok)
     539        qWarning() << "QEglContext::swapBuffersRegion2NOK():" << QEgl::errorString();
     540    return ok;
     541}
     542
     543int QEglContext::configAttrib(int name) const
     544{
     545    EGLint value;
     546    EGLBoolean success = eglGetConfigAttrib(QEgl::display(), cfg, name, &value);
     547    if (success)
     548        return value;
     549    else
     550        return EGL_DONT_CARE;
     551}
     552
     553typedef EGLImageKHR (EGLAPIENTRY *_eglCreateImageKHR)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*);
     554typedef EGLBoolean (EGLAPIENTRY *_eglDestroyImageKHR)(EGLDisplay, EGLImageKHR);
     555
     556// Defined in qegl.cpp:
     557static _eglCreateImageKHR qt_eglCreateImageKHR = 0;
     558static _eglDestroyImageKHR qt_eglDestroyImageKHR = 0;
     559
     560typedef EGLBoolean (EGLAPIENTRY *_eglSwapBuffersRegion2NOK)(EGLDisplay, EGLSurface, EGLint, const EGLint*);
     561
     562static _eglSwapBuffersRegion2NOK qt_eglSwapBuffersRegion2NOK = 0;
     563
     564EGLDisplay QEgl::display()
     565{
     566    static EGLDisplay dpy = EGL_NO_DISPLAY;
    395567    if (!QEglContextTracker::displayOpened()) {
    396568        dpy = eglGetDisplay(nativeDisplay());
    397569        QEglContextTracker::setDisplayOpened();
    398570        if (dpy == EGL_NO_DISPLAY) {
    399             qWarning("QEglContext::display(): Falling back to EGL_DEFAULT_DISPLAY");
     571            qWarning("QEgl::display(): Falling back to EGL_DEFAULT_DISPLAY");
    400572            dpy = eglGetDisplay(EGLNativeDisplayType(EGL_DEFAULT_DISPLAY));
    401573        }
    402574        if (dpy == EGL_NO_DISPLAY) {
    403             qWarning("QEglContext::display(): Can't even open the default display");
     575            qWarning("QEgl::display(): Can't even open the default display");
    404576            return EGL_NO_DISPLAY;
    405577        }
    406578
    407579        if (!eglInitialize(dpy, NULL, NULL)) {
    408             qWarning() << "QEglContext::display(): Cannot initialize EGL display:" << errorString(eglGetError());
     580            qWarning() << "QEgl::display(): Cannot initialize EGL display:" << QEgl::errorString();
    409581            return EGL_NO_DISPLAY;
    410582        }
     583
     584        // Resolve the egl extension function pointers:
     585#if (defined(EGL_KHR_image) || defined(EGL_KHR_image_base)) && !defined(EGL_EGLEXT_PROTOTYPES)
     586        if (QEgl::hasExtension("EGL_KHR_image") || QEgl::hasExtension("EGL_KHR_image_base")) {
     587            qt_eglCreateImageKHR = (_eglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR");
     588            qt_eglDestroyImageKHR = (_eglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR");
     589        }
     590#endif
     591
     592        if (QEgl::hasExtension("EGL_NOK_swap_region2")) {
     593            qt_eglSwapBuffersRegion2NOK = (_eglSwapBuffersRegion2NOK) eglGetProcAddress("eglSwapBuffersRegion2NOK");
     594        }
    411595    }
    412596
     
    414598}
    415599
    416 #if !defined(Q_WS_X11) && !defined(Q_WS_WINCE) // WinCE & X11 implement this properly
    417 EGLNativeDisplayType QEglContext::nativeDisplay()
    418 {
    419     return EGL_DEFAULT_DISPLAY;
    420 }
    421 #endif
     600EGLImageKHR QEgl::eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
     601{
     602    if (qt_eglCreateImageKHR)
     603        return qt_eglCreateImageKHR(dpy, ctx, target, buffer, attrib_list);
     604
     605    QEgl::display(); // Initialises function pointers
     606    if (qt_eglCreateImageKHR)
     607        return qt_eglCreateImageKHR(dpy, ctx, target, buffer, attrib_list);
     608
     609    qWarning("QEgl::eglCreateImageKHR() called but EGL_KHR_image(_base) extension not present");
     610    return 0;
     611}
     612
     613EGLBoolean QEgl::eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
     614{
     615    if (qt_eglDestroyImageKHR)
     616        return qt_eglDestroyImageKHR(dpy, img);
     617
     618    QEgl::display(); // Initialises function pointers
     619    if (qt_eglDestroyImageKHR)
     620        return qt_eglDestroyImageKHR(dpy, img);
     621
     622    qWarning("QEgl::eglDestroyImageKHR() called but EGL_KHR_image(_base) extension not present");
     623    return 0;
     624}
     625
     626EGLBoolean QEgl::eglSwapBuffersRegion2NOK(EGLDisplay dpy, EGLSurface surface, EGLint count, const EGLint *rects)
     627{
     628    if (qt_eglSwapBuffersRegion2NOK)
     629        return qt_eglSwapBuffersRegion2NOK(dpy, surface, count, rects);
     630
     631    QEgl::display(); // Initialises function pointers
     632    if (qt_eglSwapBuffersRegion2NOK)
     633        return qt_eglSwapBuffersRegion2NOK(dpy, surface, count, rects);
     634
     635    qWarning("QEgl::eglSwapBuffersRegion2NOK() called but EGL_NOK_swap_region2 extension not present");
     636    return 0;
     637}
     638
     639#ifndef Q_WS_X11
     640EGLSurface QEgl::createSurface(QPaintDevice *device, EGLConfig cfg, const QEglProperties *properties)
     641{
     642    // Create the native drawable for the paint device.
     643    int devType = device->devType();
     644    EGLNativePixmapType pixmapDrawable = 0;
     645    EGLNativeWindowType windowDrawable = 0;
     646    bool ok;
     647    if (devType == QInternal::Pixmap) {
     648        pixmapDrawable = nativePixmap(static_cast<QPixmap *>(device));
     649        ok = (pixmapDrawable != 0);
     650    } else if (devType == QInternal::Widget) {
     651        windowDrawable = nativeWindow(static_cast<QWidget *>(device));
     652        ok = (windowDrawable != 0);
     653    } else {
     654        ok = false;
     655    }
     656    if (!ok) {
     657        qWarning("QEglContext::createSurface(): Cannot create the native EGL drawable");
     658        return EGL_NO_SURFACE;
     659    }
     660
     661    // Create the EGL surface to draw into, based on the native drawable.
     662    const int *props;
     663    if (properties)
     664        props = properties->properties();
     665    else
     666        props = 0;
     667    EGLSurface surf;
     668    if (devType == QInternal::Widget)
     669        surf = eglCreateWindowSurface(QEgl::display(), cfg, windowDrawable, props);
     670    else
     671        surf = eglCreatePixmapSurface(QEgl::display(), cfg, pixmapDrawable, props);
     672    if (surf == EGL_NO_SURFACE) {
     673        qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError());
     674    }
     675    return surf;
     676}
     677#endif
     678
    422679
    423680// Return the error string associated with a specific code.
    424 QString QEglContext::errorString(EGLint code)
     681QString QEgl::errorString(EGLint code)
    425682{
    426683    static const char * const errors[] = {
     
    449706
    450707// Dump all of the EGL configurations supported by the system.
    451 void QEglContext::dumpAllConfigs()
     708void QEgl::dumpAllConfigs()
    452709{
    453710    QEglProperties props;
     
    458715    eglGetConfigs(display(), configs, count, &count);
    459716    for (EGLint index = 0; index < count; ++index) {
    460         props = configProperties(configs[index]);
     717        props = QEglProperties(configs[index]);
    461718        qWarning() << props.toString();
    462719    }
     
    464721}
    465722
    466 QString QEglContext::extensions()
    467 {
    468     const char* exts = eglQueryString(QEglContext::display(), EGL_EXTENSIONS);
     723QString QEgl::extensions()
     724{
     725    const char* exts = eglQueryString(QEgl::display(), EGL_EXTENSIONS);
    469726    return QString(QLatin1String(exts));
    470727}
    471728
    472 bool QEglContext::hasExtension(const char* extensionName)
     729bool QEgl::hasExtension(const char* extensionName)
    473730{
    474731    QList<QByteArray> extensions =
    475732        QByteArray(reinterpret_cast<const char *>
    476             (eglQueryString(QEglContext::display(), EGL_EXTENSIONS))).split(' ');
     733            (eglQueryString(QEgl::display(), EGL_EXTENSIONS))).split(' ');
    477734    return extensions.contains(extensionName);
    478735}
  • trunk/src/gui/egl/qegl_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5454//
    5555
    56 #include <QtCore/qsize.h>
    57 #include <QtGui/qimage.h>
    58 
    59 #include <private/qeglproperties_p.h>
    60 
    6156QT_BEGIN_INCLUDE_NAMESPACE
    6257
     58#ifndef QT_NO_EGL
     59#if defined(QT_OPENGL_ES_2)
     60#   include <GLES2/gl2.h>
     61#endif
     62
     63#if defined(QT_GLES_EGL)
     64#   include <GLES/egl.h>
     65#else
     66#   include <EGL/egl.h>
     67#endif
     68#if !defined(EGL_VERSION_1_2)
     69typedef unsigned int EGLenum;
     70typedef void *EGLClientBuffer;
     71#endif
     72#else
     73
     74//types from egltypes.h for compiling stub without EGL headers
     75typedef int EGLBoolean;
     76typedef int EGLint;
     77typedef int EGLenum;
     78typedef int    NativeDisplayType;
     79typedef void*  NativeWindowType;
     80typedef void*  NativePixmapType;
     81typedef int EGLDisplay;
     82typedef int EGLConfig;
     83typedef int EGLSurface;
     84typedef int EGLContext;
     85typedef int EGLClientBuffer;
     86#define EGL_NONE            0x3038  /* Attrib list terminator */
     87
     88#endif
     89
     90#if defined(Q_WS_X11)
     91// If <EGL/egl.h> included <X11/Xlib.h>, then the global namespace
     92// may have been polluted with X #define's.  The following makes sure
     93// the X11 headers were included properly and then cleans things up.
     94#include <X11/Xlib.h>
     95#include <X11/Xutil.h>
     96#undef Bool
     97#undef Status
     98#undef None
     99#undef KeyPress
     100#undef KeyRelease
     101#undef FocusIn
     102#undef FocusOut
     103#undef Type
     104#undef FontChange
     105#undef CursorShape
     106#undef Unsorted
     107#undef GrayScale
     108#endif
     109
     110// Internally we use the EGL-prefixed native types which are used in EGL >= 1.3.
     111// For older versions of EGL, we have to define these types ourselves here:
    63112#if !defined(EGL_VERSION_1_3) && !defined(QEGL_NATIVE_TYPES_DEFINED)
    64113#undef EGLNativeWindowType
     
    70119#define QEGL_NATIVE_TYPES_DEFINED 1
    71120#endif
     121
    72122QT_END_INCLUDE_NAMESPACE
    73123
     124#include <QtGui/qpaintdevice.h>
     125#include <QFlags>
     126
    74127QT_BEGIN_NAMESPACE
    75128
    76 class Q_GUI_EXPORT QEglContext
    77 {
    78 public:
    79     QEglContext();
    80     ~QEglContext();
    81 
    82     bool isValid() const;
    83     bool isCurrent() const;
    84     bool isSharing() const { return sharing; }
    85 
    86     QEgl::API api() const { return apiType; }
    87     void setApi(QEgl::API api) { apiType = api; }
    88 
    89     bool chooseConfig(const QEglProperties& properties, QEgl::PixelFormatMatch match = QEgl::ExactPixelFormat);
    90     bool createContext(QEglContext *shareContext = 0, const QEglProperties *properties = 0);
    91     void destroyContext();
    92     EGLSurface createSurface(QPaintDevice *device, const QEglProperties *properties = 0);
    93     void destroySurface(EGLSurface surface);
    94 
    95     bool makeCurrent(EGLSurface surface);
    96     bool doneCurrent();
    97     bool lazyDoneCurrent();
    98     bool swapBuffers(EGLSurface surface);
    99 
    100     void waitNative();
    101     void waitClient();
    102 
    103     bool configAttrib(int name, EGLint *value) const;
    104 
    105     static void clearError();
    106     static EGLint error();
    107     static QString errorString(EGLint code);
    108 
    109     static EGLDisplay display();
    110 
    111     EGLContext context() const { return ctx; }
    112     void setContext(EGLContext context) { ctx = context; ownsContext = false;}
    113 
    114     EGLConfig config() const { return cfg; }
    115     void setConfig(EGLConfig config) { cfg = config; }
    116 
    117     QEglProperties configProperties(EGLConfig cfg = 0) const;
    118 
    119     void dumpAllConfigs();
    120 
    121     static QString extensions();
    122     static bool hasExtension(const char* extensionName);
    123 
    124 private:
    125     QEgl::API apiType;
    126     EGLContext ctx;
    127     EGLConfig cfg;
    128     EGLSurface currentSurface;
    129     bool current;
    130     bool ownsContext;
    131     bool sharing;
    132 
    133     static EGLDisplay dpy;
    134     static EGLNativeDisplayType nativeDisplay();
    135 
    136     static QEglContext *currentContext(QEgl::API api);
    137     static void setCurrentContext(QEgl::API api, QEglContext *context);
    138 };
     129#define QEGL_NO_CONFIG ((EGLConfig)-1)
     130
     131#ifndef EGLAPIENTRY
     132#define EGLAPIENTRY
     133#endif
     134
     135// Try to get some info to debug the symbian build failues:
     136#ifdef Q_OS_SYMBIAN
     137
     138#ifdef EGL_KHR_image
     139#warning "EGL_KHR_image is defined"
     140#else
     141#warning "EGL_KHR_image is NOT defined"
     142#endif
     143
     144#ifdef EGL_KHR_image_base
     145#warning "EGL_KHR_image_base is defined"
     146#else
     147#warning "EGL_KHR_image_base is NOT defined"
     148#endif
     149
     150#ifdef EGL_EGLEXT_PROTOTYPES
     151#warning "EGL_EGLEXT_PROTOTYPES is defined"
     152#else
     153#warning "EGL_EGLEXT_PROTOTYPES NOT not defined"
     154#endif
     155
     156#endif
     157
     158
     159// Declare/define the bits of EGL_KHR_image_base we need:
     160#if !defined(EGL_KHR_image) && !defined(EGL_KHR_image_base)
     161#ifdef Q_OS_SYMBIAN
     162//symbian version of eglext.h differs from the khronos reference
     163typedef int EGLImageKHR;
     164#else
     165typedef void *EGLImageKHR;
     166#endif
     167
     168#define EGL_NO_IMAGE_KHR            ((EGLImageKHR)0)
     169#define EGL_IMAGE_PRESERVED_KHR     0x30D2
     170#define EGL_KHR_image_base
     171#endif
     172
     173#if !defined(EGL_KHR_image) && !defined(EGL_KHR_image_pixmap)
     174#define EGL_NATIVE_PIXMAP_KHR       0x30B0
     175#define EGL_KHR_image_pixmap
     176#endif
     177
     178
     179class QEglProperties;
     180
     181namespace QEgl {
     182    enum API
     183    {
     184        OpenGL,
     185        OpenVG
     186    };
     187
     188    enum PixelFormatMatch
     189    {
     190        ExactPixelFormat,
     191        BestPixelFormat
     192    };
     193
     194    enum ConfigOption
     195    {
     196        NoOptions   = 0,
     197        Translucent = 0x01,
     198        Renderable  = 0x02  // Config will be compatable with the paint engines (VG or GL)
     199    };
     200    Q_DECLARE_FLAGS(ConfigOptions, ConfigOption)
     201
     202    // Most of the time we use the same config for things like widgets & pixmaps, so rather than
     203    // go through the eglChooseConfig loop every time, we use defaultConfig, which will return
     204    // the config for a particular device/api/option combo. This function assumes that once a
     205    // config is chosen for a particular combo, it's safe to always use that combo.
     206    Q_GUI_EXPORT EGLConfig  defaultConfig(int devType, API api, ConfigOptions options);
     207
     208    Q_GUI_EXPORT EGLConfig  chooseConfig(const QEglProperties* configAttribs, QEgl::PixelFormatMatch match = QEgl::ExactPixelFormat);
     209    Q_GUI_EXPORT EGLSurface createSurface(QPaintDevice *device, EGLConfig cfg, const QEglProperties *surfaceAttribs = 0);
     210
     211    Q_GUI_EXPORT void dumpAllConfigs();
     212
     213#ifdef QT_NO_EGL
     214    Q_GUI_EXPORT QString errorString(EGLint code = 0);
     215#else
     216    Q_GUI_EXPORT QString errorString(EGLint code = eglGetError());
     217#endif
     218
     219    Q_GUI_EXPORT QString extensions();
     220    Q_GUI_EXPORT bool hasExtension(const char* extensionName);
     221
     222    Q_GUI_EXPORT EGLDisplay display();
     223
     224    Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay();
     225    Q_GUI_EXPORT EGLNativeWindowType  nativeWindow(QWidget*);
     226    Q_GUI_EXPORT EGLNativePixmapType  nativePixmap(QPixmap*);
     227
     228    // Extension functions
     229    Q_GUI_EXPORT EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
     230    Q_GUI_EXPORT EGLBoolean  eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img);
     231    Q_GUI_EXPORT EGLBoolean eglSwapBuffersRegion2NOK(EGLDisplay dpy, EGLSurface surface, EGLint count, const EGLint *rects);
     232
     233#ifdef Q_WS_X11
     234    Q_GUI_EXPORT VisualID getCompatibleVisualId(EGLConfig config);
     235#endif
     236}
     237
     238Q_DECLARE_OPERATORS_FOR_FLAGS(QEgl::ConfigOptions)
    139239
    140240QT_END_NAMESPACE
    141241
    142 #endif // QEGL_P_H
     242#endif //QEGL_P_H
  • trunk/src/gui/egl/qegl_qws.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4343#include <QtGui/qpixmap.h>
    4444#include <QtGui/qwidget.h>
     45
    4546#include "qegl_p.h"
     47#include "qeglcontext_p.h"
    4648
    4749#if !defined(QT_NO_EGL)
     
    5355
    5456QT_BEGIN_NAMESPACE
    55 
    56 // Create the surface for a QPixmap, QImage, or QWidget.
    57 // We don't have QGLScreen to create EGL surfaces for us,
    58 // so surface creation needs to be done in QtOpenGL or
    59 // QtOpenVG for Qt/Embedded.
    60 EGLSurface QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties)
    61 {
    62     Q_UNUSED(device);
    63     Q_UNUSED(properties);
    64     return EGL_NO_SURFACE;
    65 }
    6657
    6758static QScreen *screenForDevice(QPaintDevice *device)
     
    10293}
    10394
     95EGLNativeDisplayType QEgl::nativeDisplay()
     96{
     97    return  EGLNativeDisplayType(EGL_DEFAULT_DISPLAY);
     98}
     99
     100EGLNativeWindowType QEgl::nativeWindow(QWidget* widget)
     101{
     102    return (EGLNativeWindowType)(widget->winId()); // Might work
     103}
     104
     105EGLNativePixmapType QEgl::nativePixmap(QPixmap*)
     106{
     107    qWarning("QEgl: EGL pixmap surfaces not supported on QWS");
     108    return (EGLNativePixmapType)0;
     109}
     110
     111
    104112QT_END_NAMESPACE
    105113
  • trunk/src/gui/egl/qegl_stub.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4646
    4747#include "qegl_p.h"
     48#include "qeglcontext_p.h"
     49
    4850
    4951QT_BEGIN_NAMESPACE
     
    5557
    5658#define NOEGL noegl(__FUNCTION__);
    57 
    58 EGLDisplay QEglContext::dpy = 0;
    5959
    6060QEglContext::QEglContext()
    6161    : apiType(QEgl::OpenGL)
    6262    , ctx(0)
    63     , cfg(0)
     63    , cfg(QEGL_NO_CONFIG)
    6464    , currentSurface(0)
    6565    , current(false)
     
    8585    NOEGL
    8686    return false;
     87}
     88
     89EGLConfig QEgl::defaultConfig(int devType, API api, ConfigOptions options)
     90{
     91    Q_UNUSED(devType)
     92    Q_UNUSED(api)
     93    Q_UNUSED(options)
     94    NOEGL
     95    return QEGL_NO_CONFIG;
     96}
     97
     98
     99// Choose a configuration that matches "properties".
     100EGLConfig QEgl::chooseConfig(const QEglProperties* properties, QEgl::PixelFormatMatch match)
     101{
     102    Q_UNUSED(properties)
     103    Q_UNUSED(match)
     104    NOEGL
     105    return QEGL_NO_CONFIG;
    87106}
    88107
     
    158177}
    159178
    160 bool QEglContext::configAttrib(int name, EGLint *value) const
     179bool QEglContext::swapBuffersRegion2NOK(EGLSurface surface, const QRegion *region)
     180{
     181    Q_UNUSED(surface)
     182    Q_UNUSED(region)
     183    NOEGL
     184    return false;
     185}
     186
     187int QEglContext::configAttrib(int name) const
    161188{
    162189    Q_UNUSED(name)
    163     Q_UNUSED(value)
    164     NOEGL
    165     return false;
    166 }
    167 
    168 void QEglContext::clearError()
    169 {
    170     NOEGL
    171     return;
    172 }
    173 
    174 EGLint QEglContext::error()
    175 {
    176     NOEGL
    177     return 0;
    178 }
    179 
    180 EGLDisplay QEglContext::display()
    181 {
    182     NOEGL
    183     return 0;
    184 }
     190    NOEGL
     191    return 0;
     192}
     193
     194EGLDisplay QEgl::display()
     195{
     196    NOEGL
     197    return 0;
     198}
     199
     200EGLImageKHR QEgl::eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
     201{
     202    Q_UNUSED(dpy)
     203    Q_UNUSED(ctx)
     204    Q_UNUSED(target)
     205    Q_UNUSED(buffer)
     206    Q_UNUSED(attrib_list)
     207    NOEGL
     208    return 0;
     209}
     210
     211EGLBoolean QEgl::eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
     212{
     213    Q_UNUSED(dpy)
     214    Q_UNUSED(img)
     215    NOEGL
     216    return 0;
     217}
     218
     219EGLBoolean QEgl::eglSwapBuffersRegion2NOK(EGLDisplay dpy, EGLSurface surface, EGLint count, const EGLint *rects)
     220{
     221    Q_UNUSED(dpy);
     222    Q_UNUSED(surface);
     223    Q_UNUSED(count);
     224    Q_UNUSED(rects);
     225    NOEGL
     226    return 0;
     227}
     228
     229#ifndef Q_WS_X11
     230EGLSurface QEgl::createSurface(QPaintDevice *device, EGLConfig cfg, const QEglProperties *properties)
     231{
     232    Q_UNUSED(device)
     233    Q_UNUSED(cfg)
     234    Q_UNUSED(properties)
     235    NOEGL
     236    return 0;
     237}
     238#endif
     239
    185240
    186241// Return the error string associated with a specific code.
    187 QString QEglContext::errorString(EGLint code)
     242QString QEgl::errorString(EGLint code)
    188243{
    189244    Q_UNUSED(code)
     
    193248
    194249// Dump all of the EGL configurations supported by the system.
    195 void QEglContext::dumpAllConfigs()
    196 {
    197     NOEGL
    198 }
    199 
    200 QString QEglContext::extensions()
     250void QEgl::dumpAllConfigs()
     251{
     252    NOEGL
     253}
     254
     255QString QEgl::extensions()
    201256{
    202257    NOEGL
     
    204259}
    205260
    206 bool QEglContext::hasExtension(const char* extensionName)
     261bool QEgl::hasExtension(const char* extensionName)
    207262{
    208263    Q_UNUSED(extensionName)
     
    225280}
    226281
    227 EGLNativeDisplayType QEglContext::nativeDisplay()
    228 {
    229     NOEGL
    230     return 0;
    231 }
    232 
    233 void QEglContext::waitClient()
    234 {
    235     NOEGL
    236 }
    237 
    238 void QEglContext::waitNative()
    239 {
    240     NOEGL
    241 }
    242 
    243 QEglProperties QEglContext::configProperties(EGLConfig cfg) const
    244 {
    245     Q_UNUSED(cfg)
    246     NOEGL
    247     return QEglProperties();
     282EGLNativeDisplayType QEgl::nativeDisplay()
     283{
     284    NOEGL
     285    return 0;
     286}
     287
     288EGLNativeWindowType QEgl::nativeWindow(QWidget* widget)
     289{
     290    Q_UNUSED(widget)
     291    NOEGL
     292    return (EGLNativeWindowType)0;
     293}
     294
     295EGLNativePixmapType QEgl::nativePixmap(QPixmap*)
     296{
     297    NOEGL
     298    return (EGLNativePixmapType)0;
    248299}
    249300
  • trunk/src/gui/egl/qegl_symbian.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4343#include <QtGui/qpixmap.h>
    4444#include <QtGui/qwidget.h>
     45
    4546#include "qegl_p.h"
     47#include "qeglcontext_p.h"
    4648
    4749#include <coecntrl.h>
     
    4951QT_BEGIN_NAMESPACE
    5052
    51 EGLSurface QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties)
     53EGLNativeDisplayType QEgl::nativeDisplay()
    5254{
    53     // Create the native drawable for the paint device.
    54     int devType = device->devType();
    55     EGLNativePixmapType pixmapDrawable = 0;
    56     EGLNativeWindowType windowDrawable = 0;
    57     bool ok;
    58     if (devType == QInternal::Pixmap) {
    59         pixmapDrawable = 0;
    60         ok = (pixmapDrawable != 0);
    61     } else if (devType == QInternal::Widget) {
    62         QWidget *w = static_cast<QWidget *>(device);
    63         windowDrawable = (EGLNativeWindowType)(w->winId()->DrawableWindow());
    64         ok = (windowDrawable != 0);
    65     } else {
    66         ok = false;
    67     }
    68     if (!ok) {
    69         qWarning("QEglContext::createSurface(): Cannot create the native EGL drawable");
    70         return EGL_NO_SURFACE;
    71     }
     55    return EGL_DEFAULT_DISPLAY;
     56}
    7257
    73     // Create the EGL surface to draw into, based on the native drawable.
    74     const int *props;
    75     if (properties)
    76         props = properties->properties();
    77     else
    78         props = 0;
    79     EGLSurface surf;
    80     if (devType == QInternal::Widget)
    81         surf = eglCreateWindowSurface(dpy, cfg, windowDrawable, props);
    82     else
    83         surf = eglCreatePixmapSurface(dpy, cfg, pixmapDrawable, props);
    84     if (surf == EGL_NO_SURFACE)
    85         qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError());
    86     return surf;
     58EGLNativeWindowType QEgl::nativeWindow(QWidget* widget)
     59{
     60    return (EGLNativeWindowType)(widget->winId()->DrawableWindow());
     61}
     62
     63EGLNativePixmapType QEgl::nativePixmap(QPixmap*)
     64{
     65    qWarning("QEgl: EGL pixmap surfaces not implemented yet on Symbian");
     66    return (EGLNativePixmapType)0;
    8767}
    8868
  • trunk/src/gui/egl/qegl_wince.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4343#include <QtGui/qpixmap.h>
    4444#include <QtGui/qwidget.h>
     45
    4546#include "qegl_p.h"
     47#include "qeglcontext_p.h"
    4648
    4749#include <windows.h>
     
    5052QT_BEGIN_NAMESPACE
    5153
    52 EGLSurface QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties)
    53 {
    54     // Create the native drawable for the paint device.
    55     int devType = device->devType();
    56     EGLNativePixmapType pixmapDrawable = 0;
    57     EGLNativeWindowType windowDrawable = 0;
    58     bool ok;
    59     if (devType == QInternal::Pixmap) {
    60         pixmapDrawable = 0;
    61         ok = (pixmapDrawable != 0);
    62     } else if (devType == QInternal::Widget) {
    63         windowDrawable = (EGLNativeWindowType)(static_cast<QWidget *>(device))->winId();
    64         ok = (windowDrawable != 0);
    65     } else {
    66         ok = false;
    67     }
    68     if (!ok) {
    69         qWarning("QEglContext::createSurface(): Cannot create the native EGL drawable");
    70         return EGL_NO_SURFACE;
    71     }
    72 
    73     // Create the EGL surface to draw into, based on the native drawable.
    74     const int *props;
    75     if (properties)
    76         props = properties->properties();
    77     else
    78         props = 0;
    79     EGLSurface surf;
    80     if (devType == QInternal::Widget)
    81         surf = eglCreateWindowSurface(dpy, cfg, windowDrawable, props);
    82     else
    83         surf = eglCreatePixmapSurface(dpy, cfg, pixmapDrawable, props);
    84     if (surf == EGL_NO_SURFACE) {
    85         qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError());
    86     }
    87     return surf;
    88 }
    89 
    90 EGLNativeDisplayType QEglContext::nativeDisplay()
     54EGLNativeDisplayType QEgl::nativeDisplay()
    9155{
    9256    HDC myDc = GetDC(0);
    93 
    9457    if (!myDc) {
    9558        qWarning("QEglContext::nativeDisplay(): WinCE display is not open");
     
    9760    }
    9861    return EGLNativeDisplayType(myDc);
     62}
     63
     64EGLNativeWindowType QEgl::nativeWindow(QWidget* widget)
     65{
     66    return (EGLNativeWindowType)(widget->winId());
     67}
     68
     69EGLNativePixmapType QEgl::nativePixmap(QPixmap*)
     70{
     71    qWarning("QEgl: EGL pixmap surfaces not supported on WinCE");
     72    return (EGLNativePixmapType)0;
    9973}
    10074
  • trunk/src/gui/egl/qegl_x11.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4242#include <QtCore/qdebug.h>
    4343
    44 #include <private/qt_x11_p.h>
     44#include <QtGui/private/qt_x11_p.h>
    4545#include <QtGui/qx11info_x11.h>
    46 #include <private/qpixmapdata_p.h>
    47 #include <private/qpixmap_x11_p.h>
     46#include <QtGui/private/qpixmapdata_p.h>
     47#include <QtGui/private/qpixmap_x11_p.h>
     48#include <QtGui/private/qimagepixmapcleanuphooks_p.h>
    4849
    4950#include <QtGui/qpaintdevice.h>
    5051#include <QtGui/qpixmap.h>
    5152#include <QtGui/qwidget.h>
    52 #include "qegl_p.h"
    53 
     53#include <QtGui/qcolormap.h>
     54
     55#include "QtGui/private/qegl_p.h"
     56#include "QtGui/private/qeglcontext_p.h"
    5457
    5558QT_BEGIN_NAMESPACE
    5659
    57 EGLSurface QEglContext::createSurface(QPaintDevice *device, const QEglProperties *properties)
    58 {
    59     // Create the native drawable for the paint device.
    60     int devType = device->devType();
    61     EGLNativePixmapType pixmapDrawable = 0;
    62     EGLNativeWindowType windowDrawable = 0;
    63     bool ok;
    64     if (devType == QInternal::Pixmap) {
    65         pixmapDrawable = (EGLNativePixmapType)(static_cast<QPixmap *>(device))->handle();
    66         ok = (pixmapDrawable != 0);
    67     } else if (devType == QInternal::Widget) {
    68         windowDrawable = (EGLNativeWindowType)(static_cast<QWidget *>(device))->winId();
    69         ok = (windowDrawable != 0);
    70     } else {
    71         ok = false;
    72     }
    73     if (!ok) {
    74         qWarning("QEglContext::createSurface(): Cannot create the native EGL drawable");
    75         return EGL_NO_SURFACE;
    76     }
    77 
    78     // Create the EGL surface to draw into, based on the native drawable.
    79     const int *props;
    80     if (properties)
    81         props = properties->properties();
    82     else
    83         props = 0;
    84     EGLSurface surf;
    85     if (devType == QInternal::Widget)
    86         surf = eglCreateWindowSurface(dpy, cfg, windowDrawable, props);
    87     else
    88         surf = eglCreatePixmapSurface(dpy, cfg, pixmapDrawable, props);
    89     if (surf == EGL_NO_SURFACE) {
    90         qWarning() << "QEglContext::createSurface(): Unable to create EGL surface:"
    91                    << errorString(eglGetError());
    92     }
    93     return surf;
    94 }
    95 
    96 EGLNativeDisplayType QEglContext::nativeDisplay()
     60
     61EGLNativeDisplayType QEgl::nativeDisplay()
    9762{
    9863    Display *xdpy = QX11Info::display();
     
    10267    }
    10368    return EGLNativeDisplayType(xdpy);
     69}
     70
     71EGLNativeWindowType QEgl::nativeWindow(QWidget* widget)
     72{
     73    return (EGLNativeWindowType)(widget->winId());
     74}
     75
     76EGLNativePixmapType QEgl::nativePixmap(QPixmap* pixmap)
     77{
     78    return (EGLNativePixmapType)(pixmap->handle());
    10479}
    10580
     
    154129}
    155130
     131//#define QT_DEBUG_X11_VISUAL_SELECTION 1
     132
     133VisualID QEgl::getCompatibleVisualId(EGLConfig config)
     134{
     135    VisualID    visualId = 0;
     136    EGLint      eglValue = 0;
     137
     138    EGLint configRedSize = 0;
     139    eglGetConfigAttrib(display(), config, EGL_RED_SIZE, &configRedSize);
     140
     141    EGLint configGreenSize = 0;
     142    eglGetConfigAttrib(display(), config, EGL_GREEN_SIZE, &configGreenSize);
     143
     144    EGLint configBlueSize = 0;
     145    eglGetConfigAttrib(display(), config, EGL_BLUE_SIZE, &configBlueSize);
     146
     147    EGLint configAlphaSize = 0;
     148    eglGetConfigAttrib(display(), config, EGL_ALPHA_SIZE, &configAlphaSize);
     149
     150    eglGetConfigAttrib(display(), config, EGL_CONFIG_ID, &eglValue);
     151    int configId = eglValue;
     152
     153    // See if EGL provided a valid VisualID:
     154    eglGetConfigAttrib(display(), config, EGL_NATIVE_VISUAL_ID, &eglValue);
     155    visualId = (VisualID)eglValue;
     156    if (visualId) {
     157        // EGL has suggested a visual id, so get the rest of the visual info for that id:
     158        XVisualInfo visualInfoTemplate;
     159        memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
     160        visualInfoTemplate.visualid = visualId;
     161
     162        XVisualInfo *chosenVisualInfo;
     163        int matchingCount = 0;
     164        chosenVisualInfo = XGetVisualInfo(X11->display, VisualIDMask, &visualInfoTemplate, &matchingCount);
     165        if (chosenVisualInfo) {
     166            // Skip size checks if implementation supports non-matching visual
     167            // and config (http://bugreports.qt.nokia.com/browse/QTBUG-9444).
     168            if (QEgl::hasExtension("EGL_NV_post_convert_rounding")) {
     169                XFree(chosenVisualInfo);
     170                return visualId;
     171            }
     172
     173            int visualRedSize = countBits(chosenVisualInfo->red_mask);
     174            int visualGreenSize = countBits(chosenVisualInfo->green_mask);
     175            int visualBlueSize = countBits(chosenVisualInfo->blue_mask);
     176            int visualAlphaSize = -1; // Need XRender to tell us the alpha channel size
     177
     178#if !defined(QT_NO_XRENDER)
     179            if (X11->use_xrender) {
     180                // If we have XRender, actually check the visual supplied by EGL is ARGB
     181                XRenderPictFormat *format;
     182                format = XRenderFindVisualFormat(X11->display, chosenVisualInfo->visual);
     183                if (format && (format->type == PictTypeDirect))
     184                    visualAlphaSize = countBits(format->direct.alphaMask);
     185            }
     186#endif
     187
     188            bool visualMatchesConfig = false;
     189            if ( visualRedSize == configRedSize &&
     190                 visualGreenSize == configGreenSize &&
     191                 visualBlueSize == configBlueSize )
     192            {
     193                // We need XRender to check the alpha channel size of the visual. If we don't have
     194                // the alpha size, we don't check it against the EGL config's alpha size.
     195                if (visualAlphaSize >= 0)
     196                    visualMatchesConfig = visualAlphaSize == configAlphaSize;
     197                else
     198                    visualMatchesConfig = true;
     199            }
     200
     201            if (!visualMatchesConfig) {
     202                if (visualAlphaSize >= 0) {
     203                    qWarning("Warning: EGL suggested using X Visual ID %d (ARGB%d%d%d%d) for EGL config %d (ARGB%d%d%d%d), but this is incompatable",
     204                             (int)visualId, visualAlphaSize, visualRedSize, visualGreenSize, visualBlueSize,
     205                             configId, configAlphaSize, configRedSize, configGreenSize, configBlueSize);
     206                } else {
     207                    qWarning("Warning: EGL suggested using X Visual ID %d (RGB%d%d%d) for EGL config %d (RGB%d%d%d), but this is incompatable",
     208                             (int)visualId, visualRedSize, visualGreenSize, visualBlueSize,
     209                             configId, configRedSize, configGreenSize, configBlueSize);
     210                }
     211                visualId = 0;
     212            }
     213        } else {
     214            qWarning("Warning: EGL suggested using X Visual ID %d for EGL config %d, but that isn't a valid ID",
     215                     (int)visualId, configId);
     216            visualId = 0;
     217        }
     218        XFree(chosenVisualInfo);
     219    }
     220#ifdef QT_DEBUG_X11_VISUAL_SELECTION
     221    else
     222        qDebug("EGL did not suggest a VisualID (EGL_NATIVE_VISUAL_ID was zero) for EGLConfig %d", configId);
     223#endif
     224
     225    if (visualId) {
     226#ifdef QT_DEBUG_X11_VISUAL_SELECTION
     227        if (configAlphaSize > 0)
     228            qDebug("Using ARGB Visual ID %d provided by EGL for config %d", (int)visualId, configId);
     229        else
     230            qDebug("Using Opaque Visual ID %d provided by EGL for config %d", (int)visualId, configId);
     231#endif
     232        return visualId;
     233    }
     234
     235
     236    // If EGL didn't give us a valid visual ID, try XRender
     237#if !defined(QT_NO_XRENDER)
     238    if (!visualId && X11->use_xrender) {
     239        XVisualInfo visualInfoTemplate;
     240        memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
     241
     242        visualInfoTemplate.c_class = TrueColor;
     243
     244        XVisualInfo *matchingVisuals;
     245        int matchingCount = 0;
     246        matchingVisuals = XGetVisualInfo(X11->display,
     247                                         VisualClassMask,
     248                                         &visualInfoTemplate,
     249                                         &matchingCount);
     250
     251        for (int i = 0; i < matchingCount; ++i) {
     252            XRenderPictFormat *format;
     253            format = XRenderFindVisualFormat(X11->display, matchingVisuals[i].visual);
     254
     255            // Check the format for the visual matches the EGL config
     256            if ( (countBits(format->direct.redMask) == configRedSize) &&
     257                 (countBits(format->direct.greenMask) == configGreenSize) &&
     258                 (countBits(format->direct.blueMask) == configBlueSize) &&
     259                 (countBits(format->direct.alphaMask) == configAlphaSize) )
     260            {
     261                visualId = matchingVisuals[i].visualid;
     262                break;
     263            }
     264        }
     265        if (matchingVisuals)
     266            XFree(matchingVisuals);
     267
     268    }
     269    if (visualId) {
     270# ifdef QT_DEBUG_X11_VISUAL_SELECTION
     271        if (configAlphaSize > 0)
     272            qDebug("Using ARGB Visual ID %d provided by XRender for EGL config %d", (int)visualId, configId);
     273        else
     274            qDebug("Using Opaque Visual ID %d provided by XRender for EGL config %d", (int)visualId, configId);
     275# endif // QT_DEBUG_X11_VISUAL_SELECTION
     276        return visualId;
     277    }
     278# ifdef QT_DEBUG_X11_VISUAL_SELECTION
     279    else
     280        qDebug("Failed to find an XVisual which matches EGL config %d using XRender", configId);
     281# endif // QT_DEBUG_X11_VISUAL_SELECTION
     282
     283#endif //!defined(QT_NO_XRENDER)
     284
     285
     286    // Finally, if XRender also failed to find a visual (or isn't present), try to
     287    // use XGetVisualInfo and only use the bit depths to match on:
     288    if (!visualId) {
     289        XVisualInfo visualInfoTemplate;
     290        memset(&visualInfoTemplate, 0, sizeof(XVisualInfo));
     291        XVisualInfo *matchingVisuals;
     292        int matchingCount = 0;
     293
     294        visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize + configAlphaSize;
     295        matchingVisuals = XGetVisualInfo(X11->display,
     296                                         VisualDepthMask,
     297                                         &visualInfoTemplate,
     298                                         &matchingCount);
     299        if (!matchingVisuals) {
     300            // Try again without taking the alpha channel into account:
     301            visualInfoTemplate.depth = configRedSize + configGreenSize + configBlueSize;
     302            matchingVisuals = XGetVisualInfo(X11->display,
     303                                             VisualDepthMask,
     304                                             &visualInfoTemplate,
     305                                             &matchingCount);
     306        }
     307
     308        if (matchingVisuals) {
     309            visualId = matchingVisuals[0].visualid;
     310            XFree(matchingVisuals);
     311        }
     312    }
     313
     314    if (visualId) {
     315#ifdef QT_DEBUG_X11_VISUAL_SELECTION
     316        qDebug("Using Visual ID %d provided by XGetVisualInfo for EGL config %d", (int)visualId, configId);
     317#endif
     318        return visualId;
     319    }
     320
     321    qWarning("Unable to find an X11 visual which matches EGL config %d", configId);
     322    return (VisualID)0;
     323}
     324
     325void qt_set_winid_on_widget(QWidget* w, Qt::HANDLE id)
     326{
     327    w->create(id);
     328}
     329
     330
     331// NOTE: The X11 version of createSurface will re-create the native drawable if it's visual doesn't
     332// match the one for the passed in EGLConfig
     333EGLSurface QEgl::createSurface(QPaintDevice *device, EGLConfig config, const QEglProperties *unusedProperties)
     334{
     335    Q_UNUSED(unusedProperties);
     336
     337    int devType = device->devType();
     338
     339    if (devType == QInternal::Pbuffer) {
     340        // TODO
     341        return EGL_NO_SURFACE;
     342    }
     343
     344    QX11PixmapData *x11PixmapData = 0;
     345    if (devType == QInternal::Pixmap) {
     346        QPixmapData *pmd = static_cast<QPixmap*>(device)->data_ptr().data();
     347        if (pmd->classId() == QPixmapData::X11Class)
     348            x11PixmapData = static_cast<QX11PixmapData*>(pmd);
     349        else {
     350            // TODO: Replace the pixmap's data with a new QX11PixmapData
     351            qWarning("WARNING: Creating an EGL surface on a QPixmap is only supported for QX11PixmapData");
     352            return EGL_NO_SURFACE;
     353        }
     354    } else if ((devType != QInternal::Widget) && (devType != QInternal::Pbuffer)) {
     355        qWarning("WARNING: Creating an EGLSurface for device type %d isn't supported", devType);
     356        return EGL_NO_SURFACE;
     357    }
     358
     359    VisualID visualId = QEgl::getCompatibleVisualId(config);
     360    EGLint alphaSize;
     361    eglGetConfigAttrib(QEgl::display(), config, EGL_ALPHA_SIZE, &alphaSize);
     362
     363    if (devType == QInternal::Widget) {
     364        QWidget *widget = static_cast<QWidget*>(device);
     365
     366        VisualID currentVisualId = 0;
     367        if (widget->testAttribute(Qt::WA_WState_Created))
     368            currentVisualId = XVisualIDFromVisual((Visual*)widget->x11Info().visual());
     369
     370        if (currentVisualId != visualId) {
     371            // The window is either not created or has the wrong visual. Either way, we need
     372            // to create a window with the correct visual and call create() on the widget:
     373
     374            bool visible = widget->isVisible();
     375            if (visible)
     376                widget->hide();
     377
     378            XVisualInfo visualInfo;
     379            visualInfo.visualid = visualId;
     380            {
     381                XVisualInfo *visualInfoPtr;
     382                int matchingCount = 0;
     383                visualInfoPtr = XGetVisualInfo(widget->x11Info().display(), VisualIDMask,
     384                                               &visualInfo, &matchingCount);
     385                Q_ASSERT(visualInfoPtr); // visualId really should be valid!
     386                visualInfo = *visualInfoPtr;
     387                XFree(visualInfoPtr);
     388            }
     389
     390            Window parentWindow = RootWindow(widget->x11Info().display(), widget->x11Info().screen());
     391            if (widget->parentWidget())
     392                parentWindow = widget->parentWidget()->winId();
     393
     394            XSetWindowAttributes windowAttribs;
     395            QColormap colmap = QColormap::instance(widget->x11Info().screen());
     396            windowAttribs.background_pixel = colmap.pixel(widget->palette().color(widget->backgroundRole()));
     397            windowAttribs.border_pixel = colmap.pixel(Qt::black);
     398
     399            unsigned int valueMask = CWBackPixel|CWBorderPixel;
     400            if (alphaSize > 0) {
     401                windowAttribs.colormap = XCreateColormap(widget->x11Info().display(), parentWindow,
     402                                                         visualInfo.visual, AllocNone);
     403                valueMask |= CWColormap;
     404            }
     405
     406            Window window = XCreateWindow(widget->x11Info().display(), parentWindow,
     407                                          widget->x(), widget->y(), widget->width(), widget->height(),
     408                                          0, visualInfo.depth, InputOutput, visualInfo.visual,
     409                                          valueMask, &windowAttribs);
     410
     411            // This is a nasty hack to get round the fact that we can't be a friend of QWidget:
     412            qt_set_winid_on_widget(widget, window);
     413
     414            if (visible)
     415                widget->show();
     416        }
     417
     418        // At this point, the widget's window should be created and have the correct visual. Now we
     419        // just need to create the EGL surface for it:
     420        EGLSurface surf = eglCreateWindowSurface(QEgl::display(), config, (EGLNativeWindowType)widget->winId(), 0);
     421        if (surf == EGL_NO_SURFACE)
     422            qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError());
     423        return surf;
     424    }
     425
     426    if (x11PixmapData) {
     427        // X11 Pixmaps are only created with a depth, so that's all we need to check
     428        EGLint configDepth;
     429        eglGetConfigAttrib(QEgl::display(), config, EGL_BUFFER_SIZE , &configDepth);
     430        if (x11PixmapData->depth() != configDepth) {
     431            // The bit depths are wrong which means the EGLConfig isn't compatable with
     432            // this pixmap. So we need to replace the pixmap's existing data with a new
     433            // one which is created with the correct depth:
     434
     435#ifndef QT_NO_XRENDER
     436            if (configDepth == 32) {
     437                qWarning("Warning: EGLConfig's depth (32) != pixmap's depth (%d), converting to ARGB32",
     438                         x11PixmapData->depth());
     439                x11PixmapData->convertToARGB32(true);
     440            } else
     441#endif
     442            {
     443                qWarning("Warning: EGLConfig's depth (%d) != pixmap's depth (%d)",
     444                         configDepth, x11PixmapData->depth());
     445            }
     446        }
     447
     448        QEglProperties surfaceAttribs;
     449
     450        // If the pixmap can't be bound to a texture, it's pretty useless
     451        surfaceAttribs.setValue(EGL_TEXTURE_TARGET, EGL_TEXTURE_2D);
     452        if (alphaSize > 0)
     453            surfaceAttribs.setValue(EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA);
     454        else
     455            surfaceAttribs.setValue(EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGB);
     456
     457        EGLSurface surf = eglCreatePixmapSurface(QEgl::display(), config,
     458                                                 (EGLNativePixmapType) x11PixmapData->handle(),
     459                                                 surfaceAttribs.properties());
     460        x11PixmapData->gl_surface = (void*)surf;
     461        QImagePixmapCleanupHooks::enableCleanupHooks(x11PixmapData);
     462        return surf;
     463    }
     464
     465    return EGL_NO_SURFACE;
     466}
     467
    156468QT_END_NAMESPACE
  • trunk/src/gui/egl/qeglproperties.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4444
    4545#include "qeglproperties_p.h"
     46#include "qeglcontext_p.h"
    4647
    4748QT_BEGIN_NAMESPACE
    48 
    49 #include "qegl_p.h"
    50 
    5149
    5250// Initialize a property block.
     
    6159    for (int name = 0x3020; name <= 0x304F; ++name) {
    6260        EGLint value;
    63         if (name != EGL_NONE && eglGetConfigAttrib(QEglContext::display(), cfg, name, &value))
     61        if (name != EGL_NONE && eglGetConfigAttrib(QEgl::display(), cfg, name, &value))
    6462            setValue(name, value);
    6563    }
     
    8381    case EGL_BLUE_SIZE: return 0;
    8482    case EGL_ALPHA_SIZE: return 0;
    85 #if defined(EGL_LUMINANCE_SIZE)
     83#ifdef EGL_LUMINANCE_SIZE
    8684    case EGL_LUMINANCE_SIZE: return 0;
    8785#endif
    88 #if defined(EGL_ALPHA_MASK_SIZE)
     86#ifdef EGL_ALPHA_MASK_SIZE
    8987    case EGL_ALPHA_MASK_SIZE: return 0;
    9088#endif
    91 #if defined(EGL_BIND_TO_TEXTURE_RGB)
     89#ifdef EGL_BIND_TO_TEXTURE_RGB
    9290    case EGL_BIND_TO_TEXTURE_RGB: return EGL_DONT_CARE;
    9391#endif
    94 #if defined(EGL_BIND_TO_TEXTURE_RGBA)
     92#ifdef EGL_BIND_TO_TEXTURE_RGBA
    9593    case EGL_BIND_TO_TEXTURE_RGBA: return EGL_DONT_CARE;
    9694#endif
    97 #if defined(EGL_COLOR_BUFFER_TYPE)
     95#ifdef EGL_COLOR_BUFFER_TYPE
    9896    case EGL_COLOR_BUFFER_TYPE: return EGL_RGB_BUFFER;
    9997#endif
     
    106104    case EGL_MAX_SWAP_INTERVAL: return EGL_DONT_CARE;
    107105    case EGL_MIN_SWAP_INTERVAL: return EGL_DONT_CARE;
    108 #if defined(EGL_RENDERABLE_TYPE)
     106#ifdef EGL_RENDERABLE_TYPE
    109107    case EGL_RENDERABLE_TYPE: return EGL_OPENGL_ES_BIT;
    110108#endif
     
    118116    case EGL_TRANSPARENT_BLUE_VALUE: return EGL_DONT_CARE;
    119117
    120 #if defined(EGL_VERSION_1_3)
     118#ifdef EGL_VERSION_1_3
    121119    case EGL_CONFORMANT: return 0;
    122120    case EGL_MATCH_NATIVE_PIXMAP: return EGL_NONE;
     
    166164    return false;
    167165}
     166
     167void QEglProperties::setDeviceType(int devType)
     168{
     169    if (devType == QInternal::Pixmap || devType == QInternal::Image)
     170        setValue(EGL_SURFACE_TYPE, EGL_PIXMAP_BIT);
     171    else if (devType == QInternal::Pbuffer)
     172        setValue(EGL_SURFACE_TYPE, EGL_PBUFFER_BIT);
     173    else
     174        setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT);
     175}
     176
    168177
    169178// Sets the red, green, blue, and alpha sizes based on a pixel format.
     
    207216void QEglProperties::setRenderableType(QEgl::API api)
    208217{
    209 #if defined(EGL_RENDERABLE_TYPE)
     218#ifdef EGL_RENDERABLE_TYPE
    210219#if defined(QT_OPENGL_ES_2)
    211220    if (api == QEgl::OpenGL)
     
    214223    if (api == QEgl::OpenGL)
    215224        setValue(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT);
    216 #endif
    217 #if defined(EGL_OPENVG_BIT)
     225#elif defined(EGL_OPENGL_BIT)
     226    if (api == QEgl::OpenGL)
     227        setValue(EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT);
     228#endif
     229#ifdef EGL_OPENVG_BIT
    218230    if (api == QEgl::OpenVG)
    219231        setValue(EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT);
     
    230242bool QEglProperties::reduceConfiguration()
    231243{
     244#ifdef EGL_SWAP_BEHAVIOR
     245    if (value(EGL_SWAP_BEHAVIOR) != EGL_DONT_CARE)
     246        removeValue(EGL_SWAP_BEHAVIOR);
     247#endif
     248
     249#ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT
     250    // For OpenVG, we sometimes try to create a surface using a pre-multiplied format. If we can't
     251    // find a config which supports pre-multiplied formats, remove the flag on the surface type:
     252    EGLint surfaceType = value(EGL_SURFACE_TYPE);
     253    if (surfaceType & EGL_VG_ALPHA_FORMAT_PRE_BIT) {
     254        surfaceType ^= EGL_VG_ALPHA_FORMAT_PRE_BIT;
     255        setValue(EGL_SURFACE_TYPE, surfaceType);
     256        return true;
     257    }
     258#endif
    232259    // EGL chooses configs with the highest color depth over
    233260    // those with smaller (but faster) lower color depths. One
    234261    // way around this is to set EGL_BUFFER_SIZE to 16, which
    235262    // trumps the others. Of course, there may not be a 16-bit
    236     // config avaliable, so it's the first restraint we remove.
     263    // config available, so it's the first restraint we remove.
    237264    if (value(EGL_BUFFER_SIZE) == 16) {
    238265        removeValue(EGL_BUFFER_SIZE);
     
    254281    if (removeValue(EGL_DEPTH_SIZE))
    255282        return true;
    256 #if defined(EGL_BIND_TO_TEXTURE_RGB)
     283#ifdef EGL_BIND_TO_TEXTURE_RGB
    257284    if (removeValue(EGL_BIND_TO_TEXTURE_RGB))
    258285        return true;
     
    269296        str += QLatin1String("\n   ");
    270297    str += tag;
    271 }
    272 
    273 void QEglProperties::dumpAllConfigs()
    274 {
    275     EGLint count = 0;
    276     eglGetConfigs(QEglContext::display(), 0, 0, &count);
    277     if (count < 1)
    278         return;
    279 
    280     EGLConfig *configs = new EGLConfig [count];
    281     eglGetConfigs(QEglContext::display(), configs, count, &count);
    282     for (EGLint index = 0; index < count; ++index)
    283         qWarning() << QEglProperties(configs[index]).toString();
    284     delete [] configs;
    285298}
    286299
     
    308321        if ((val & EGL_OPENGL_ES2_BIT) != 0)
    309322            types += QLatin1String("es2");
     323#endif
     324#ifdef EGL_OPENGL_BIT
     325        if ((val & EGL_OPENGL_BIT) != 0)
     326            types += QLatin1String("gl");
    310327#endif
    311328        if ((val & EGL_OPENVG_BIT) != 0)
  • trunk/src/gui/egl/qeglproperties_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5757#include <QtGui/qimage.h>
    5858
    59 QT_BEGIN_INCLUDE_NAMESPACE
    60 
    61 #ifndef QT_NO_EGL
    62 #if defined(QT_OPENGL_ES_2)
    63 #   include <GLES2/gl2.h>
    64 #endif
    65 
    66 #if defined(QT_GLES_EGL)
    67 #   include <GLES/egl.h>
    68 #else
    69 #   include <EGL/egl.h>
    70 #endif
    71 #else
    72 
    73 //types from egltypes.h for compiling stub without EGL headers
    74 typedef int EGLBoolean;
    75 typedef int EGLint;
    76 typedef int EGLenum;
    77 typedef int    NativeDisplayType;
    78 typedef void*  NativeWindowType;
    79 typedef void*  NativePixmapType;
    80 typedef int EGLDisplay;
    81 typedef int EGLConfig;
    82 typedef int EGLSurface;
    83 typedef int EGLContext;
    84 typedef int EGLClientBuffer;
    85 #define EGL_NONE            0x3038  /* Attrib list terminator */
    86 
    87 #endif
    88 
    89 
    90 
    91 #if defined(Q_WS_X11)
    92 // If <EGL/egl.h> included <X11/Xlib.h>, then the global namespace
    93 // may have been polluted with X #define's.  The following makes sure
    94 // the X11 headers were included properly and then cleans things up.
    95 #include <X11/Xlib.h>
    96 #include <X11/Xutil.h>
    97 #undef Bool
    98 #undef Status
    99 #undef None
    100 #undef KeyPress
    101 #undef KeyRelease
    102 #undef FocusIn
    103 #undef FocusOut
    104 #undef Type
    105 #undef FontChange
    106 #undef CursorShape
    107 #endif
    108 
    109 QT_END_INCLUDE_NAMESPACE
     59#include <QtGui/private/qegl_p.h>
    11060
    11161QT_BEGIN_NAMESPACE
    112 
    113 namespace QEgl {
    114     enum API
    115     {
    116         OpenGL,
    117         OpenVG
    118     };
    119 
    120     enum PixelFormatMatch
    121     {
    122         ExactPixelFormat,
    123         BestPixelFormat
    124     };
    125 }
    12662
    12763class QX11Info;
     
    14783    void setVisualFormat(const QX11Info *xinfo);
    14884#endif
     85    void setDeviceType(int devType);
     86    void setPaintDeviceFormat(QPaintDevice *dev);
    14987    void setRenderableType(QEgl::API api);
    150 
    151     void setPaintDeviceFormat(QPaintDevice *dev);
    15288
    15389    bool reduceConfiguration();
    15490
    15591    QString toString() const;
    156 
    157     static void dumpAllConfigs();
    15892
    15993private:
  • trunk/src/gui/egl/qeglproperties_stub.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4444
    4545#include "qeglproperties_p.h"
     46#include "qeglcontext_p.h"
    4647
    4748QT_BEGIN_NAMESPACE
     
    9192}
    9293
     94void QEglProperties::setDeviceType(int devType)
     95{
     96    Q_UNUSED(devType)
     97    NOEGL
     98}
     99
     100
    93101// Sets the red, green, blue, and alpha sizes based on a pixel format.
    94102// Normally used to match a configuration request to the screen format.
     
    116124}
    117125
     126static void addTag(QString& str, const QString& tag)
     127{
     128    Q_UNUSED(str)
     129    Q_UNUSED(tag)
     130    NOEGL
     131}
     132
    118133// Convert a property list to a string suitable for debug output.
    119134QString QEglProperties::toString() const
     
    129144}
    130145
    131 void QEglProperties::dumpAllConfigs()
    132 {
    133     NOEGL
    134 }
    135 
    136146QT_END_NAMESPACE
    137147
Note: See TracChangeset for help on using the changeset viewer.