diff --git a/abstract_egl_backend.cpp b/abstract_egl_backend.cpp index 31bbf70dab..3e6f0c8820 100644 --- a/abstract_egl_backend.cpp +++ b/abstract_egl_backend.cpp @@ -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) diff --git a/abstract_egl_backend.h b/abstract_egl_backend.h index 965abe094c..93cce8ded4 100644 --- a/abstract_egl_backend.h +++ b/abstract_egl_backend.h @@ -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; diff --git a/backends/drm/egl_gbm_backend.cpp b/backends/drm/egl_gbm_backend.cpp index 0d7eebe9c8..afcfc986ed 100644 --- a/backends/drm/egl_gbm_backend.cpp +++ b/backends/drm/egl_gbm_backend.cpp @@ -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 extensions = QByteArray::fromRawData(eglExtensionsCString, qstrlen(eglExtensionsCString)).split(' '); + const char* eglExtensionsCString = eglQueryString(eglDisplay(), EGL_EXTENSIONS); + const QList 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, }; diff --git a/backends/virtual/egl_gbm_backend.cpp b/backends/virtual/egl_gbm_backend.cpp index 7f7eb74c4c..e1fcbab13d 100644 --- a/backends/virtual/egl_gbm_backend.cpp +++ b/backends/virtual/egl_gbm_backend.cpp @@ -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, }; diff --git a/backends/wayland/egl_wayland_backend.cpp b/backends/wayland/egl_wayland_backend.cpp index 0f5bdce6c7..c63d409f73 100644 --- a/backends/wayland/egl_wayland_backend.cpp +++ b/backends/wayland/egl_wayland_backend.cpp @@ -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 extensions = QByteArray::fromRawData(eglExtensionsCString, qstrlen(eglExtensionsCString)).split(' '); + const char* eglExtensionsCString = eglQueryString(eglDisplay(), EGL_EXTENSIONS); + const QList 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, }; diff --git a/eglonxbackend.cpp b/eglonxbackend.cpp index 314bfb287e..03cd5259cb 100644 --- a/eglonxbackend.cpp +++ b/eglonxbackend.cpp @@ -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 extensions = eglExtensions.split(' '); + const QByteArray eglExtensions = eglQueryString(dpy, EGL_EXTENSIONS); + const QList 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, };