42 #include <QtGui/qpaintdevice.h> 43 #include <QtGui/qpixmap.h> 44 #include <QtGui/qwidget.h> 45 #include <QtCore/qatomic.h> 46 #include <QtCore/qdebug.h> 52 #include "private/qt_s60_p.h" 96 , currentSurface(EGL_NO_SURFACE)
109 if (currentGLContext ==
this)
110 currentGLContext = 0;
111 if (currentVGContext ==
this)
112 currentVGContext = 0;
118 return (
ctx != EGL_NO_CONTEXT);
129 qWarning(
"QEgl::defaultConfig() - Only configs for pixmaps make sense to be read-only!");
131 EGLConfig* targetConfig = 0;
133 static EGLConfig defaultVGConfigs[] = {
144 targetConfig = &(defaultVGConfigs[0]);
146 targetConfig = &(defaultVGConfigs[1]);
148 if (options & Renderable) {
150 targetConfig = &(defaultVGConfigs[2]);
152 targetConfig = &(defaultVGConfigs[3]);
155 targetConfig = &(defaultVGConfigs[4]);
157 targetConfig = &(defaultVGConfigs[5]);
163 static EGLConfig defaultGLConfigs[] = {
176 targetConfig = &(defaultGLConfigs[0]);
178 targetConfig = &(defaultGLConfigs[1]);
181 targetConfig = &(defaultGLConfigs[2]);
183 targetConfig = &(defaultGLConfigs[3]);
185 if (options & Renderable) {
187 targetConfig = &(defaultGLConfigs[4]);
189 targetConfig = &(defaultGLConfigs[5]);
192 targetConfig = &(defaultGLConfigs[6]);
194 targetConfig = &(defaultGLConfigs[7]);
200 qWarning(
"QEgl::defaultConfig() - No default config for device/api/options combo");
203 if (*targetConfig != QEGL_NO_CONFIG)
204 return *targetConfig;
213 configId =
qgetenv(
"QT_VG_EGL_CONFIG");
215 configId =
qgetenv(
"QT_GL_EGL_CONFIG");
219 EGL_CONFIG_ID, (EGLint)configId.
toInt(),
222 EGLint configCount = 0;
223 eglChooseConfig(
display(), properties, targetConfig, 1, &configCount);
225 return *targetConfig;
226 qWarning() <<
"QEgl::defaultConfig() -" << configId <<
"appears to be invalid";
235 surfaceType = EGL_WINDOW_BIT;
238 surfaceType = EGL_PIXMAP_BIT;
241 surfaceType = EGL_PBUFFER_BIT;
244 qWarning(
"QEgl::defaultConfig() - Can't create EGL surface for %d device type", devType);
247 #ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT 251 surfaceType |= EGL_VG_ALPHA_FORMAT_PRE_BIT;
253 configAttribs.
setValue(EGL_SURFACE_TYPE, surfaceType);
255 #ifdef EGL_BIND_TO_TEXTURE_RGBA 257 if (options & Translucent)
258 configAttribs.
setValue(EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE);
260 configAttribs.
setValue(EGL_BIND_TO_TEXTURE_RGB, EGL_TRUE);
266 #if !defined(QVG_SCISSOR_CLIP) && defined(EGL_ALPHA_MASK_SIZE) 267 configAttribs.
setValue(EGL_ALPHA_MASK_SIZE, 1);
271 configAttribs.
setValue(EGL_STENCIL_SIZE, 1);
272 configAttribs.
setValue(EGL_SAMPLE_BUFFERS, 1);
273 #ifndef QT_OPENGL_ES_2 275 configAttribs.
setValue(EGL_DEPTH_SIZE, 1);
279 if (options & Translucent)
280 configAttribs.
setValue(EGL_ALPHA_SIZE, 1);
283 return *targetConfig;
296 if (!eglChooseConfig(dpy, props.
properties(), 0, 0, &matching) || !matching)
310 EGLint size = matching;
311 EGLConfig *configs =
new EGLConfig [size];
315 eglGetConfigAttrib(
display(), configs[
index], EGL_RED_SIZE, &red);
316 eglGetConfigAttrib(
display(), configs[index], EGL_GREEN_SIZE, &green);
317 eglGetConfigAttrib(
display(), configs[index], EGL_BLUE_SIZE, &blue);
318 eglGetConfigAttrib(
display(), configs[index], EGL_ALPHA_SIZE, &alpha);
319 if (red == props.
value(EGL_RED_SIZE) &&
320 green == props.
value(EGL_GREEN_SIZE) &&
321 blue == props.
value(EGL_BLUE_SIZE) &&
322 (props.
value(EGL_ALPHA_SIZE) == 0 ||
323 alpha == props.
value(EGL_ALPHA_SIZE))) {
324 cfg = configs[
index];
332 #ifdef EGL_BIND_TO_TEXTURE_RGBA 336 if (props.
value(EGL_BIND_TO_TEXTURE_RGBA) == EGL_DONT_CARE &&
337 props.
value(EGL_BIND_TO_TEXTURE_RGB) == EGL_DONT_CARE)
340 qWarning() <<
"QEglContext::chooseConfig(): Could not find a suitable EGL configuration";
365 #ifdef EGL_OPENGL_ES_API 367 eglBindAPI(EGL_OPENGL_ES_API);
370 #ifdef EGL_OPENGL_API 372 eglBindAPI(EGL_OPENGL_API);
374 #endif //defined(QT_OPENGL_ES) 375 #ifdef EGL_OPENVG_API 377 eglBindAPI(EGL_OPENVG_API);
384 #ifdef QT_OPENGL_ES_2 386 contextProps.
setValue(EGL_CONTEXT_CLIENT_VERSION, 2);
389 if (shareContext && shareContext->
ctx == EGL_NO_CONTEXT)
393 if (
ctx == EGL_NO_CONTEXT) {
400 if (
ctx == EGL_NO_CONTEXT) {
402 if (
ctx == EGL_NO_CONTEXT) {
405 S60->eglSurfaceCreationError =
true;
417 if (surface != EGL_NO_SURFACE) {
420 eglDestroySurface(
display(), surface);
429 ctx = EGL_NO_CONTEXT;
435 if (
ctx == EGL_NO_CONTEXT) {
436 qWarning() <<
"QEglContext::makeCurrent(): Cannot make invalid context current";
440 if (surface == EGL_NO_SURFACE) {
441 qWarning() <<
"QEglContext::makeCurrent(): Cannot make invalid surface current";
470 #ifdef EGL_OPENGL_ES_API 472 eglBindAPI(EGL_OPENGL_ES_API);
474 #ifdef EGL_OPENVG_API 476 eglBindAPI(EGL_OPENVG_API);
489 if (
ctx == EGL_NO_CONTEXT)
499 #ifdef EGL_OPENGL_ES_API 501 eglBindAPI(EGL_OPENGL_ES_API);
503 #ifdef EGL_OPENVG_API 505 eglBindAPI(EGL_OPENVG_API);
508 bool ok = eglMakeCurrent(
QEgl::display(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
527 if(
ctx == EGL_NO_CONTEXT)
549 count = qrects.
size();
551 gl_rects = arr.
data();
552 for (i = 0; i < count; i++) {
553 QRect qrect = qrects[i];
555 gl_rects[4 * i + 0] = qrect.
x();
556 gl_rects[4 * i + 1] = qrect.
y();
557 gl_rects[4 * i + 2] = qrect.
width();
558 gl_rects[4 * i + 3] = qrect.
height();
571 EGLBoolean success = eglGetConfigAttrib(
QEgl::display(),
cfg, name, &value);
575 return EGL_DONT_CARE;
591 static EGLDisplay dpy = EGL_NO_DISPLAY;
595 if (dpy == EGL_NO_DISPLAY) {
596 qWarning(
"QEgl::display(): Falling back to EGL_DEFAULT_DISPLAY");
599 if (dpy == EGL_NO_DISPLAY) {
600 qWarning(
"QEgl::display(): Can't even open the default display");
601 return EGL_NO_DISPLAY;
604 if (!eglInitialize(dpy, NULL, NULL)) {
606 return EGL_NO_DISPLAY;
610 #if (defined(EGL_KHR_image) || defined(EGL_KHR_image_base)) && !defined(EGL_EGLEXT_PROTOTYPES) 634 qWarning(
"QEgl::eglCreateImageKHR() called but EGL_KHR_image(_base) extension not present");
647 qWarning(
"QEgl::eglDestroyImageKHR() called but EGL_KHR_image(_base) extension not present");
660 qWarning(
"QEgl::eglSwapBuffersRegion2NOK() called but EGL_NOK_swap_region2 extension not present");
668 int devType = device->
devType();
673 pixmapDrawable =
nativePixmap(static_cast<QPixmap *>(device));
674 ok = (pixmapDrawable != 0);
676 windowDrawable =
nativeWindow(static_cast<QWidget *>(device));
677 ok = (windowDrawable != 0);
682 qWarning(
"QEglContext::createSurface(): Cannot create the native EGL drawable");
683 return EGL_NO_SURFACE;
692 EGLSurface surf = EGL_NO_SURFACE;
705 static int tries = 4;
708 while (tries-- > 0) {
713 if (surf == EGL_NO_SURFACE) {
714 EGLint
error = eglGetError();
715 if (error == EGL_BAD_ALLOC) {
717 User::After(1000 * 250);
721 qWarning(
"QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", error);
722 S60->eglSurfaceCreationError =
true;
733 if (surf == EGL_NO_SURFACE) {
734 qWarning(
"QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError());
745 static const char *
const errors[] = {
747 "Not initialized (0x3001)",
748 "Bad access (0x3002)",
749 "Bad alloc (0x3003)",
750 "Bad attribute (0x3004)",
751 "Bad config (0x3005)",
752 "Bad context (0x3006)",
753 "Bad current surface (0x3007)",
754 "Bad display (0x3008)",
755 "Bad match (0x3009)",
756 "Bad native pixmap (0x300A)",
757 "Bad native window (0x300B)",
758 "Bad parameter (0x300C)",
759 "Bad surface (0x300D)",
760 "Context lost (0x300E)" 762 if (code >= 0x3000 && code <= 0x300E) {
774 if (!eglGetConfigs(
display(), 0, 0, &count) || count < 1)
776 EGLConfig *configs =
new EGLConfig [count];
777 eglGetConfigs(
display(), configs, count, &count);
787 const char* exts = eglQueryString(
QEgl::display(), EGL_EXTENSIONS);
796 return extensions.
contains(extensionName);
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
EGLSurface createSurface(QPaintDevice *device, const QEglProperties *properties=0)
#define QT_END_NAMESPACE
This macro expands to.
bool createContext(QEglContext *shareContext=0, const QEglProperties *properties=0)
NativePixmapType EGLNativePixmapType
const EGLint * properties() const
The QByteArray class provides an array of bytes.
int value(int name) const
static bool match(const uchar *found, const char *target, uint len)
int width() const
Returns the width of the rectangle.
bool chooseConfig(const QEglProperties &properties, QEgl::PixelFormatMatch match=QEgl::ExactPixelFormat)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int height() const
Returns the height of the rectangle.
The QString class provides a Unicode character string.
void setValue(int name, int value)
#define Q_BASIC_ATOMIC_INITIALIZER(a)
Q_GUI_EXPORT QString extensions()
bool swapBuffers(EGLSurface surface)
NativeWindowType EGLNativeWindowType
Q_GUI_EXPORT EGLNativePixmapType nativePixmap(QPixmap *)
virtual int devType() const
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
bool swapBuffersRegion2NOK(EGLSurface surface, const QRegion *region)
EGLContext context() const
static QBasicAtomicInt displayOpen
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_GUI_EXPORT EGLDisplay display()
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
void setRenderableType(QEgl::API api)
static bool displayOpened()
Q_GUI_EXPORT EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
static QEglContext *volatile currentGLContext
static _eglSwapBuffersRegion2NOK qt_eglSwapBuffersRegion2NOK
EGLSurface currentSurface
Q_CORE_EXPORT void qWarning(const char *,...)
static void setDisplayOpened()
The QRegion class specifies a clip region for a painter.
bool reduceConfiguration()
Q_GUI_EXPORT bool hasExtension(const char *extensionName)
Q_GUI_EXPORT EGLConfig defaultConfig(int devType, API api, ConfigOptions options)
int configAttrib(int name) const
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays...
static QEglContext * currentContext(QEgl::API api)
Q_GUI_EXPORT EGLSurface createSurface(QPaintDevice *device, EGLConfig cfg, const QEglProperties *surfaceAttribs=0)
Q_GUI_EXPORT EGLNativeDisplayType nativeDisplay()
int y() const
Returns the y-coordinate of the rectangle's top edge.
Q_GUI_EXPORT void dumpAllConfigs()
bool makeCurrent(EGLSurface surface)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
int x() const
Returns the x-coordinate of the rectangle's left edge.
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
void destroySurface(EGLSurface surface)
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
The QRect class defines a rectangle in the plane using integer precision.
Q_GUI_EXPORT EGLBoolean eglSwapBuffersRegion2NOK(EGLDisplay dpy, EGLSurface surface, EGLint count, const EGLint *rects)
static const QCssKnownValue properties[NumProperties - 1]
static QBasicAtomicInt contexts
NativeDisplayType EGLNativeDisplayType
EGLBoolean(EGLAPIENTRY * _eglSwapBuffersRegion2NOK)(EGLDisplay, EGLSurface, EGLint, const EGLint *)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
static _eglCreateImageKHR qt_eglCreateImageKHR
Q_GUI_EXPORT EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
Q_GUI_EXPORT EGLConfig chooseConfig(const QEglProperties *configAttribs, QEgl::PixelFormatMatch match=QEgl::ExactPixelFormat)
static void setCurrentContext(QEgl::API api, QEglContext *context)
EGLBoolean(EGLAPIENTRY * _eglDestroyImageKHR)(EGLDisplay, EGLImageKHR)
int size() const
Returns the number of items in the vector.
static QEglContext *volatile currentVGContext
Q_GUI_EXPORT EGLNativeWindowType nativeWindow(QWidget *)
EGLImageKHR(EGLAPIENTRY * _eglCreateImageKHR)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint *)
static _eglDestroyImageKHR qt_eglDestroyImageKHR