Move egl context creation into AbstractEglContext
Code was more or less copied into each backend, so it's better to have a shared implementation.
This commit is contained in:
parent
3a610ec9f6
commit
6d96b8c4af
7 changed files with 50 additions and 149 deletions
|
@ -182,6 +182,46 @@ bool AbstractEglBackend::isOpenGLES() const
|
|||
return QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES;
|
||||
}
|
||||
|
||||
bool AbstractEglBackend::createContext()
|
||||
{
|
||||
EGLContext ctx = EGL_NO_CONTEXT;
|
||||
if (isOpenGLES()) {
|
||||
const EGLint context_attribs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
ctx = eglCreateContext(m_display, 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 QByteArray eglExtensions = eglQueryString(m_display, 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(m_display, config(), EGL_NO_CONTEXT, context_attribs_31_core);
|
||||
|
||||
if (ctx == EGL_NO_CONTEXT)
|
||||
ctx = eglCreateContext(m_display, config(), EGL_NO_CONTEXT, context_attribs_legacy);
|
||||
}
|
||||
|
||||
if (ctx == EGL_NO_CONTEXT) {
|
||||
qCCritical(KWIN_CORE) << "Create Context failed";
|
||||
return false;
|
||||
}
|
||||
m_context = ctx;
|
||||
return true;
|
||||
}
|
||||
|
||||
AbstractEglTexture::AbstractEglTexture(SceneOpenGL::Texture *texture, AbstractEglBackend *backend)
|
||||
: SceneOpenGL::TexturePrivate()
|
||||
, q(texture)
|
||||
|
|
|
@ -51,9 +51,6 @@ protected:
|
|||
void setEglDisplay(const EGLDisplay &display) {
|
||||
m_display = display;
|
||||
}
|
||||
void setContext(const EGLContext &context) {
|
||||
m_context = context;
|
||||
}
|
||||
void setSurface(const EGLSurface &surface) {
|
||||
m_surface = surface;
|
||||
}
|
||||
|
@ -70,6 +67,8 @@ protected:
|
|||
bool hasClientExtension(const QByteArray &ext) const;
|
||||
bool isOpenGLES() const;
|
||||
|
||||
bool createContext();
|
||||
|
||||
private:
|
||||
EGLDisplay m_display = EGL_NO_DISPLAY;
|
||||
EGLSurface m_surface = EGL_NO_SURFACE;
|
||||
|
|
|
@ -131,42 +131,9 @@ bool EglGbmBackend::initRenderingContext()
|
|||
{
|
||||
initBufferConfigs();
|
||||
|
||||
EGLContext context = EGL_NO_CONTEXT;
|
||||
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
|
||||
};
|
||||
|
||||
const EGLint context_attribs_legacy[] = {
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
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 (!createContext()) {
|
||||
return false;
|
||||
}
|
||||
setContext(context);
|
||||
|
||||
const auto outputs = m_backend->outputs();
|
||||
for (DrmOutput *drmOutput: outputs) {
|
||||
|
|
|
@ -102,19 +102,9 @@ bool EglHwcomposerBackend::initRenderingContext()
|
|||
return false;
|
||||
}
|
||||
|
||||
EGLContext context = EGL_NO_CONTEXT;
|
||||
const EGLint context_attribs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
context = eglCreateContext(eglDisplay(), config(), EGL_NO_CONTEXT, context_attribs);
|
||||
|
||||
if (context == EGL_NO_CONTEXT) {
|
||||
qCCritical(KWIN_HWCOMPOSER) << "Create Context failed";
|
||||
if (!createContext()) {
|
||||
return false;
|
||||
}
|
||||
setContext(context);
|
||||
|
||||
m_nativeSurface = m_backend->createSurface();
|
||||
EGLSurface surface = eglCreateWindowSurface(eglDisplay(), config(), (EGLNativeWindowType)static_cast<ANativeWindow*>(m_nativeSurface), nullptr);
|
||||
|
|
|
@ -112,39 +112,9 @@ bool EglGbmBackend::initRenderingContext()
|
|||
return false;
|
||||
}
|
||||
|
||||
EGLContext context = EGL_NO_CONTEXT;
|
||||
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
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
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 (!createContext()) {
|
||||
return false;
|
||||
}
|
||||
setContext(context);
|
||||
setSurfaceLessContext(true);
|
||||
|
||||
return makeCurrent();
|
||||
|
|
|
@ -113,42 +113,9 @@ bool EglWaylandBackend::initRenderingContext()
|
|||
{
|
||||
initBufferConfigs();
|
||||
|
||||
EGLContext context = EGL_NO_CONTEXT;
|
||||
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
|
||||
};
|
||||
|
||||
const EGLint context_attribs_legacy[] = {
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
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";
|
||||
if (!createContext()) {
|
||||
return false;
|
||||
}
|
||||
setContext(context);
|
||||
|
||||
if (!m_wayland->surface()) {
|
||||
return false;
|
||||
|
|
|
@ -230,43 +230,11 @@ bool EglOnXBackend::initRenderingContext()
|
|||
}
|
||||
setSurface(surface);
|
||||
|
||||
EGLContext ctx = EGL_NO_CONTEXT;
|
||||
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
|
||||
};
|
||||
|
||||
const EGLint context_attribs_legacy[] = {
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
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";
|
||||
if (!createContext()) {
|
||||
return false;
|
||||
}
|
||||
setContext(ctx);
|
||||
|
||||
if (eglMakeCurrent(dpy, surface, surface, ctx) == EGL_FALSE) {
|
||||
if (eglMakeCurrent(dpy, surface, surface, context()) == EGL_FALSE) {
|
||||
qCCritical(KWIN_CORE) << "Make Context Current failed";
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue