Remove GL context creation from CompositingPrefs
Whether creating the OpenGL context succeeds or not had no influence in any decisions on the used settings for OpenGL based compositing. The only valid information CompositingPrefs still detects is whether direct rendering should be used which is performed out of process and does not require a context. So overall the context creation is not needed and can be removed. REVIEW: 104778
This commit is contained in:
parent
2fc0b8074b
commit
fdd804bdf4
2 changed files with 1 additions and 220 deletions
|
@ -134,33 +134,7 @@ void CompositingPrefs::detect()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTICE: this is intended to workaround broken GL implementations that successfully segfault
|
#ifndef KWIN_HAVE_OPENGLES
|
||||||
// on glXQuery :-(
|
|
||||||
// we tag GL as unsafe. It *must* be reset before every return, and in case we "unexpectedly"
|
|
||||||
// end (aka "segfaulted") we know that we shall not try again
|
|
||||||
KSharedConfigPtr config = KSharedConfig::openConfig("kwinrc");
|
|
||||||
KConfigGroup gl_workaround_config = KConfigGroup(config, "Compositing");
|
|
||||||
gl_workaround_config.writeEntry("OpenGLIsUnsafe", true);
|
|
||||||
gl_workaround_config.sync();
|
|
||||||
|
|
||||||
#ifdef KWIN_HAVE_OPENGLES
|
|
||||||
bool haveContext = false;
|
|
||||||
bool canDetect = false;
|
|
||||||
EGLDisplay dpy = eglGetCurrentDisplay();
|
|
||||||
if (dpy != EGL_NO_DISPLAY) {
|
|
||||||
EGLContext ctx = eglGetCurrentContext();
|
|
||||||
if (ctx != EGL_NO_CONTEXT) {
|
|
||||||
haveContext = true;
|
|
||||||
canDetect = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!haveContext) {
|
|
||||||
canDetect = initEGLContext();
|
|
||||||
}
|
|
||||||
if (!haveContext) {
|
|
||||||
deleteEGLContext();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// HACK: This is needed for AIGLX
|
// HACK: This is needed for AIGLX
|
||||||
const bool forceIndirect = qstrcmp(qgetenv("LIBGL_ALWAYS_INDIRECT"), "1") == 0;
|
const bool forceIndirect = qstrcmp(qgetenv("LIBGL_ALWAYS_INDIRECT"), "1") == 0;
|
||||||
if (!forceIndirect && qstrcmp(qgetenv("KWIN_DIRECT_GL"), "1") != 0) {
|
if (!forceIndirect && qstrcmp(qgetenv("KWIN_DIRECT_GL"), "1") != 0) {
|
||||||
|
@ -181,182 +155,6 @@ void CompositingPrefs::detect()
|
||||||
} else {
|
} else {
|
||||||
mEnableDirectRendering = !forceIndirect;
|
mEnableDirectRendering = !forceIndirect;
|
||||||
}
|
}
|
||||||
if (!hasGlx()) {
|
|
||||||
kDebug(1212) << "No GLX available";
|
|
||||||
gl_workaround_config.writeEntry("OpenGLIsUnsafe", false);
|
|
||||||
gl_workaround_config.sync();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int glxmajor, glxminor;
|
|
||||||
glXQueryVersion(display(), &glxmajor, &glxminor);
|
|
||||||
kDebug(1212) << "glx version is " << glxmajor << "." << glxminor;
|
|
||||||
bool hasglx13 = (glxmajor > 1 || (glxmajor == 1 && glxminor >= 3));
|
|
||||||
|
|
||||||
// remember and later restore active context
|
|
||||||
GLXContext oldcontext = glXGetCurrentContext();
|
|
||||||
GLXDrawable olddrawable = glXGetCurrentDrawable();
|
|
||||||
GLXDrawable oldreaddrawable = None;
|
|
||||||
if (hasglx13)
|
|
||||||
oldreaddrawable = glXGetCurrentReadDrawable();
|
|
||||||
|
|
||||||
initGLXContext();
|
|
||||||
if (hasglx13)
|
|
||||||
glXMakeContextCurrent(display(), olddrawable, oldreaddrawable, oldcontext);
|
|
||||||
else
|
|
||||||
glXMakeCurrent(display(), olddrawable, oldcontext);
|
|
||||||
deleteGLXContext();
|
|
||||||
#endif
|
|
||||||
gl_workaround_config.writeEntry("OpenGLIsUnsafe", false);
|
|
||||||
gl_workaround_config.sync();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CompositingPrefs::initGLXContext()
|
|
||||||
{
|
|
||||||
#ifndef KWIN_HAVE_OPENGLES
|
|
||||||
mGLContext = NULL;
|
|
||||||
KXErrorHandler handler;
|
|
||||||
// Most of this code has been taken from glxinfo.c
|
|
||||||
QVector<int> attribs;
|
|
||||||
attribs << GLX_RGBA;
|
|
||||||
attribs << GLX_RED_SIZE << 1;
|
|
||||||
attribs << GLX_GREEN_SIZE << 1;
|
|
||||||
attribs << GLX_BLUE_SIZE << 1;
|
|
||||||
attribs << None;
|
|
||||||
|
|
||||||
XVisualInfo* visinfo = glXChooseVisual(display(), DefaultScreen(display()), attribs.data());
|
|
||||||
if (!visinfo) {
|
|
||||||
attribs.last() = GLX_DOUBLEBUFFER;
|
|
||||||
attribs << None;
|
|
||||||
visinfo = glXChooseVisual(display(), DefaultScreen(display()), attribs.data());
|
|
||||||
if (!visinfo) {
|
|
||||||
kDebug(1212) << "Error: couldn't find RGB GLX visual";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mGLContext = glXCreateContext(display(), visinfo, NULL, True);
|
|
||||||
if (!mGLContext) {
|
|
||||||
kDebug(1212) << "glXCreateContext failed";
|
|
||||||
XDestroyWindow(display(), mGLWindow);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
XSetWindowAttributes attr;
|
|
||||||
attr.background_pixel = 0;
|
|
||||||
attr.border_pixel = 0;
|
|
||||||
attr.colormap = XCreateColormap(display(), rootWindow(), visinfo->visual, AllocNone);
|
|
||||||
attr.event_mask = StructureNotifyMask | ExposureMask;
|
|
||||||
unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
||||||
int width = 100, height = 100;
|
|
||||||
mGLWindow = XCreateWindow(display(), rootWindow(), 0, 0, width, height,
|
|
||||||
0, visinfo->depth, InputOutput,
|
|
||||||
visinfo->visual, mask, &attr);
|
|
||||||
|
|
||||||
return glXMakeCurrent(display(), mGLWindow, mGLContext) && !handler.error(true);
|
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void CompositingPrefs::deleteGLXContext()
|
|
||||||
{
|
|
||||||
#ifndef KWIN_HAVE_OPENGLES
|
|
||||||
if (mGLContext == NULL)
|
|
||||||
return;
|
|
||||||
glXDestroyContext(display(), mGLContext);
|
|
||||||
XDestroyWindow(display(), mGLWindow);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CompositingPrefs::initEGLContext()
|
|
||||||
{
|
|
||||||
#ifdef KWIN_HAVE_OPENGLES
|
|
||||||
mEGLDisplay = eglGetDisplay(display());
|
|
||||||
if (mEGLDisplay == EGL_NO_DISPLAY) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (eglInitialize(mEGLDisplay, 0, 0) == EGL_FALSE) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
eglBindAPI(EGL_OPENGL_ES_API);
|
|
||||||
|
|
||||||
const EGLint config_attribs[] = {
|
|
||||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
||||||
EGL_RED_SIZE, 1,
|
|
||||||
EGL_GREEN_SIZE, 1,
|
|
||||||
EGL_BLUE_SIZE, 1,
|
|
||||||
EGL_ALPHA_SIZE, 0,
|
|
||||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
||||||
EGL_CONFIG_CAVEAT, EGL_NONE,
|
|
||||||
EGL_NONE,
|
|
||||||
};
|
|
||||||
|
|
||||||
EGLint count;
|
|
||||||
EGLConfig configs[1024];
|
|
||||||
eglChooseConfig(mEGLDisplay, config_attribs, configs, 1024, &count);
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
// egl_glx only supports indirect rendering, which itself does not allow GLES2
|
|
||||||
kWarning(1212) << "You might be using mesa egl_glx, which is not supported!";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
EGLint visualId = XVisualIDFromVisual((Visual*)QX11Info::appVisual());
|
|
||||||
|
|
||||||
EGLConfig config = configs[0];
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
EGLint val;
|
|
||||||
eglGetConfigAttrib(mEGLDisplay, configs[i], EGL_NATIVE_VISUAL_ID, &val);
|
|
||||||
if (visualId == val) {
|
|
||||||
config = configs[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
XSetWindowAttributes attr;
|
|
||||||
attr.background_pixel = 0;
|
|
||||||
attr.border_pixel = 0;
|
|
||||||
attr.colormap = XCreateColormap(display(), rootWindow(), (Visual*)QX11Info::appVisual(), AllocNone);
|
|
||||||
attr.event_mask = StructureNotifyMask | ExposureMask;
|
|
||||||
unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
||||||
int width = 100, height = 100;
|
|
||||||
mGLWindow = XCreateWindow(display(), rootWindow(), 0, 0, width, height,
|
|
||||||
0, QX11Info::appDepth(), InputOutput,
|
|
||||||
(Visual*)QX11Info::appVisual(), mask, &attr);
|
|
||||||
|
|
||||||
mEGLSurface = eglCreateWindowSurface(mEGLDisplay, config, mGLWindow, 0);
|
|
||||||
|
|
||||||
const EGLint context_attribs[] = {
|
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
mEGLContext = eglCreateContext(mEGLDisplay, config, EGL_NO_CONTEXT, context_attribs);
|
|
||||||
if (mEGLContext == EGL_NO_CONTEXT) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext) == EGL_FALSE) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
EGLint error = eglGetError();
|
|
||||||
if (error != EGL_SUCCESS) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void CompositingPrefs::deleteEGLContext()
|
|
||||||
{
|
|
||||||
#ifdef KWIN_HAVE_OPENGLES
|
|
||||||
eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
||||||
eglDestroyContext(mEGLDisplay, mEGLContext);
|
|
||||||
eglDestroySurface(mEGLDisplay, mEGLSurface);
|
|
||||||
eglTerminate(mEGLDisplay);
|
|
||||||
eglReleaseThread();
|
|
||||||
XDestroyWindow(display(), mGLWindow);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,25 +56,8 @@ public:
|
||||||
|
|
||||||
void detect();
|
void detect();
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
bool initGLXContext();
|
|
||||||
void deleteGLXContext();
|
|
||||||
bool initEGLContext();
|
|
||||||
void deleteEGLContext();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mEnableDirectRendering;
|
bool mEnableDirectRendering;
|
||||||
|
|
||||||
#ifdef KWIN_HAVE_OPENGLES
|
|
||||||
EGLDisplay mEGLDisplay;
|
|
||||||
EGLContext mEGLContext;
|
|
||||||
EGLSurface mEGLSurface;
|
|
||||||
#else
|
|
||||||
GLXContext mGLContext;
|
|
||||||
#endif
|
|
||||||
Window mGLWindow;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue