Runtime depend on GLES in all egl backends

As we don't have GLPLatform before the backend is fully created
the AbstractEglBackend has a new method isOpenGLES() -> bool
which determines based on QOpenGLContext::openGLModuleType().
This commit is contained in:
Martin Gräßlin 2015-10-30 12:56:03 +01:00
parent 2f065b9c6b
commit 14d943caea
6 changed files with 110 additions and 124 deletions

View file

@ -88,14 +88,10 @@ bool AbstractEglBackend::initEglAPI()
}
qCDebug(KWIN_CORE) << "Egl Initialize succeeded";
#ifdef KWIN_HAVE_OPENGLES
eglBindAPI(EGL_OPENGL_ES_API);
#else
if (eglBindAPI(EGL_OPENGL_API) == EGL_FALSE) {
if (eglBindAPI(isOpenGLES() ? EGL_OPENGL_ES_API : EGL_OPENGL_API) == EGL_FALSE) {
qCCritical(KWIN_CORE) << "bind OpenGL API failed";
return false;
}
#endif
qCDebug(KWIN_CORE) << "EGL version: " << major << "." << minor;
return true;
}
@ -178,6 +174,11 @@ void AbstractEglBackend::doneCurrent()
eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
bool AbstractEglBackend::isOpenGLES() const
{
return QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES;
}
AbstractEglTexture::AbstractEglTexture(SceneOpenGL::Texture *texture, AbstractEglBackend *backend)
: SceneOpenGL::TexturePrivate()
, q(texture)

View file

@ -68,6 +68,7 @@ protected:
void initClientExtensions();
void initWayland();
bool hasClientExtension(const QByteArray &ext) const;
bool isOpenGLES() const;
private:
EGLDisplay m_display = EGL_NO_DISPLAY;

View file

@ -132,39 +132,39 @@ bool EglGbmBackend::initRenderingContext()
initBufferConfigs();
EGLContext context = EGL_NO_CONTEXT;
#ifdef KWIN_HAVE_OPENGLES
const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
if (isOpenGLES()) {
const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs);
#else
const EGLint context_attribs_31_core[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
EGL_NONE
};
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs);
} else {
const EGLint context_attribs_31_core[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
EGL_NONE
};
const EGLint context_attribs_legacy[] = {
EGL_NONE
};
const EGLint context_attribs_legacy[] = {
EGL_NONE
};
const char* eglExtensionsCString = eglQueryString(eglDisplay(), EGL_EXTENSIONS);
const QList<QByteArray> extensions = QByteArray::fromRawData(eglExtensionsCString, qstrlen(eglExtensionsCString)).split(' ');
const char* eglExtensionsCString = eglQueryString(eglDisplay(), EGL_EXTENSIONS);
const QList<QByteArray> extensions = QByteArray::fromRawData(eglExtensionsCString, qstrlen(eglExtensionsCString)).split(' ');
// Try to create a 3.1 core context
if (options->glCoreProfile() && extensions.contains(QByteArrayLiteral("EGL_KHR_create_context")))
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_31_core);
// Try to create a 3.1 core context
if (options->glCoreProfile() && extensions.contains(QByteArrayLiteral("EGL_KHR_create_context")))
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_31_core);
if (context == EGL_NO_CONTEXT)
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_legacy);
#endif
if (context == EGL_NO_CONTEXT)
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_legacy);
}
if (context == EGL_NO_CONTEXT) {
qCCritical(KWIN_DRM) << "Create Context failed";
return false;
if (context == EGL_NO_CONTEXT) {
qCCritical(KWIN_DRM) << "Create Context failed";
return false;
}
setContext(context);
@ -233,11 +233,7 @@ bool EglGbmBackend::initBufferConfigs()
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_ALPHA_SIZE, 0,
#ifdef KWIN_HAVE_OPENGLES
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#else
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
#endif
EGL_RENDERABLE_TYPE, isOpenGLES() ? EGL_OPENGL_ES2_BIT : EGL_OPENGL_BIT,
EGL_CONFIG_CAVEAT, EGL_NONE,
EGL_NONE,
};

View file

@ -113,36 +113,36 @@ bool EglGbmBackend::initRenderingContext()
}
EGLContext context = EGL_NO_CONTEXT;
#ifdef KWIN_HAVE_OPENGLES
const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
if (isOpenGLES()) {
const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs);
#else
const EGLint context_attribs_31_core[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
EGL_NONE
};
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs);
} else {
const EGLint context_attribs_31_core[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
EGL_NONE
};
const EGLint context_attribs_legacy[] = {
EGL_NONE
};
const EGLint context_attribs_legacy[] = {
EGL_NONE
};
// Try to create a 3.1 core context
if (options->glCoreProfile() && extensions.contains(QByteArrayLiteral("EGL_KHR_create_context")))
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_31_core);
// Try to create a 3.1 core context
if (options->glCoreProfile() && extensions.contains(QByteArrayLiteral("EGL_KHR_create_context")))
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_31_core);
if (context == EGL_NO_CONTEXT)
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_legacy);
#endif
if (context == EGL_NO_CONTEXT)
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_legacy);
}
if (context == EGL_NO_CONTEXT) {
// qCCritical(KWIN_DRM) << "Create Context failed";
return false;
if (context == EGL_NO_CONTEXT) {
// qCCritical(KWIN_DRM) << "Create Context failed";
return false;
}
setContext(context);
setSurfaceLessContext(true);
@ -158,11 +158,7 @@ bool EglGbmBackend::initBufferConfigs()
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_ALPHA_SIZE, 0,
#ifdef KWIN_HAVE_OPENGLES
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#else
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
#endif
EGL_RENDERABLE_TYPE, isOpenGLES() ? EGL_OPENGL_ES2_BIT : EGL_OPENGL_BIT,
EGL_CONFIG_CAVEAT, EGL_NONE,
EGL_NONE,
};

View file

@ -114,35 +114,35 @@ bool EglWaylandBackend::initRenderingContext()
initBufferConfigs();
EGLContext context = EGL_NO_CONTEXT;
#ifdef KWIN_HAVE_OPENGLES
const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
if (isOpenGLES()) {
const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs);
#else
const EGLint context_attribs_31_core[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
EGL_NONE
};
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs);
} else {
const EGLint context_attribs_31_core[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
EGL_NONE
};
const EGLint context_attribs_legacy[] = {
EGL_NONE
};
const EGLint context_attribs_legacy[] = {
EGL_NONE
};
const char* eglExtensionsCString = eglQueryString(eglDisplay(), EGL_EXTENSIONS);
const QList<QByteArray> extensions = QByteArray::fromRawData(eglExtensionsCString, qstrlen(eglExtensionsCString)).split(' ');
const char* eglExtensionsCString = eglQueryString(eglDisplay(), EGL_EXTENSIONS);
const QList<QByteArray> extensions = QByteArray::fromRawData(eglExtensionsCString, qstrlen(eglExtensionsCString)).split(' ');
// Try to create a 3.1 core context
if (options->glCoreProfile() && extensions.contains(QByteArrayLiteral("EGL_KHR_create_context")))
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_31_core);
// Try to create a 3.1 core context
if (options->glCoreProfile() && extensions.contains(QByteArrayLiteral("EGL_KHR_create_context")))
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_31_core);
if (context == EGL_NO_CONTEXT)
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_legacy);
#endif
if (context == EGL_NO_CONTEXT)
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs_legacy);
}
if (context == EGL_NO_CONTEXT) {
qCCritical(KWIN_WAYLAND_BACKEND) << "Create Context failed";
@ -201,11 +201,7 @@ bool EglWaylandBackend::initBufferConfigs()
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_ALPHA_SIZE, 0,
#ifdef KWIN_HAVE_OPENGLES
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#else
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
#endif
EGL_RENDERABLE_TYPE, isOpenGLES() ? EGL_OPENGL_ES2_BIT : EGL_OPENGL_BIT,
EGL_CONFIG_CAVEAT, EGL_NONE,
EGL_NONE,
};

View file

@ -227,34 +227,34 @@ bool EglOnXBackend::initRenderingContext()
setSurface(surface);
EGLContext ctx = EGL_NO_CONTEXT;
#ifdef KWIN_HAVE_OPENGLES
const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
if (isOpenGLES()) {
const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
ctx = eglCreateContext(dpy, config(), EGL_NO_CONTEXT, context_attribs);
#else
const EGLint context_attribs_31_core[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
EGL_NONE
};
ctx = eglCreateContext(dpy, config(), EGL_NO_CONTEXT, context_attribs);
} else {
const EGLint context_attribs_31_core[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
EGL_CONTEXT_MINOR_VERSION_KHR, 1,
EGL_NONE
};
const EGLint context_attribs_legacy[] = {
EGL_NONE
};
const EGLint context_attribs_legacy[] = {
EGL_NONE
};
const QByteArray eglExtensions = eglQueryString(dpy, EGL_EXTENSIONS);
const QList<QByteArray> extensions = eglExtensions.split(' ');
const QByteArray eglExtensions = eglQueryString(dpy, EGL_EXTENSIONS);
const QList<QByteArray> extensions = eglExtensions.split(' ');
// Try to create a 3.1 core context
if (options->glCoreProfile() && extensions.contains("EGL_KHR_create_context"))
ctx = eglCreateContext(dpy, config(), EGL_NO_CONTEXT, context_attribs_31_core);
// Try to create a 3.1 core context
if (options->glCoreProfile() && extensions.contains("EGL_KHR_create_context"))
ctx = eglCreateContext(dpy, config(), EGL_NO_CONTEXT, context_attribs_31_core);
if (ctx == EGL_NO_CONTEXT)
ctx = eglCreateContext(dpy, config(), EGL_NO_CONTEXT, context_attribs_legacy);
#endif
if (ctx == EGL_NO_CONTEXT)
ctx = eglCreateContext(dpy, config(), EGL_NO_CONTEXT, context_attribs_legacy);
}
if (ctx == EGL_NO_CONTEXT) {
qCCritical(KWIN_CORE) << "Create Context failed";
@ -284,11 +284,7 @@ bool EglOnXBackend::initBufferConfigs()
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_ALPHA_SIZE, 0,
#ifdef KWIN_HAVE_OPENGLES
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#else
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
#endif
EGL_RENDERABLE_TYPE, isOpenGLES() ? EGL_OPENGL_ES2_BIT : EGL_OPENGL_BIT,
EGL_CONFIG_CAVEAT, EGL_NONE,
EGL_NONE,
};