Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp (210166 => 210167)
--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp 2016-12-27 12:11:14 UTC (rev 210166)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp 2016-12-27 12:11:22 UTC (rev 210167)
@@ -23,6 +23,7 @@
#include "GraphicsContext3D.h"
#include "OpenGLShims.h"
#include "PlatformDisplayX11.h"
+#include "XErrorTrapper.h"
#include <GL/glx.h>
#include <cairo.h>
#include <cstdlib>
@@ -73,6 +74,49 @@
return !!glXCreateContextAttribsARB;
}
+static GLXContext createGLXARBContext(Display* display, GLXFBConfig config, GLXContext sharingContext)
+{
+ // We want to create a context with version >= 3.2 core profile, cause that ensures that the i965 driver won't
+ // use the software renderer. If that doesn't work, we will use whatever version available. Unfortunately,
+ // there's no way to know whether glXCreateContextAttribsARB can provide an OpenGL version >= 3.2 until
+ // we actually call it and check the return value. To make things more fun, if a version >= 3.2 cannot be
+ // provided, glXCreateContextAttribsARB will throw a GLXBadFBConfig X error, causing the app to crash.
+ // So, the first time a context is requested, we set a X error trap to disable crashes with GLXBadFBConfig
+ // and then check whether the return value is a context or not.
+
+ static bool canCreate320Context = false;
+ static bool canCreate320ContextInitialized = false;
+
+ static const int contextAttributes[] = {
+ GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+ GLX_CONTEXT_MINOR_VERSION_ARB, 2,
+ 0
+ };
+
+ if (!canCreate320ContextInitialized) {
+ canCreate320ContextInitialized = true;
+
+ {
+ // Set an X error trapper that ignores errors to avoid crashing on GLXBadFBConfig. Use a scope
+ // here to limit the error trap to just this context creation call.
+ XErrorTrapper trapper(display, XErrorTrapper::Policy::Ignore);
+ GLXContext context = glXCreateContextAttribsARB(display, config, sharingContext, GL_TRUE, contextAttributes);
+ if (context) {
+ canCreate320Context = true;
+ return context;
+ }
+ }
+
+ // Creating the 3.2 context failed, so use whatever is available.
+ return glXCreateContextAttribsARB(display, config, sharingContext, GL_TRUE, nullptr);
+ }
+
+ if (canCreate320Context)
+ return glXCreateContextAttribsARB(display, config, sharingContext, GL_TRUE, contextAttributes);
+
+ return glXCreateContextAttribsARB(display, config, sharingContext, GL_TRUE, nullptr);
+}
+
std::unique_ptr<GLContextGLX> GLContextGLX::createWindowContext(GLNativeWindowType window, PlatformDisplay& platformDisplay, GLXContext sharingContext)
{
Display* display = downcast<PlatformDisplayX11>(platformDisplay).native();
@@ -99,18 +143,10 @@
ASSERT(config);
XUniqueGLXContext context;
- if (hasGLXARBCreateContextExtension(display)) {
- // Request OpenGL version 3.2 and core profile, which guarantees that the i965 driver doesn't use the software renderer.
- static const int contextAttributes[] = {
- GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
- GLX_CONTEXT_MINOR_VERSION_ARB, 2,
- 0
- };
- context.reset(glXCreateContextAttribsARB(display, config, sharingContext, GL_TRUE, contextAttributes));
- }
-
- if (!context) {
- // Fallback to legacy OpenGL version.
+ if (hasGLXARBCreateContextExtension(display))
+ context.reset(createGLXARBContext(display, config, sharingContext));
+ else {
+ // Legacy OpenGL version.
XUniquePtr<XVisualInfo> visualInfoList(glXGetVisualFromFBConfig(display, config));
context.reset(glXCreateContext(display, visualInfoList.get(), sharingContext, True));
}
@@ -147,19 +183,10 @@
return nullptr;
XUniqueGLXContext context;
-
- if (hasGLXARBCreateContextExtension(display)) {
- // Request OpenGL version 3.2 and core profile, which guarantees that the i965 driver doesn't use the software renderer.
- static const int contextAttributes[] = {
- GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
- GLX_CONTEXT_MINOR_VERSION_ARB, 2,
- 0
- };
- context.reset(glXCreateContextAttribsARB(display, configs.get()[0], sharingContext, GL_TRUE, contextAttributes));
- }
-
- if (!context) {
- // Fallback to legacy OpenGL version.
+ if (hasGLXARBCreateContextExtension(display))
+ context.reset(createGLXARBContext(display, configs.get()[0], sharingContext));
+ else {
+ // Legacy OpenGL version.
context.reset(glXCreateNewContext(display, configs.get()[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE));
}