detect and refuse to run on nouveau

This commit is contained in:
Damien Elmes 2018-12-18 19:29:34 +10:00
parent a6c34fd79f
commit 4c6c0d428b
2 changed files with 52 additions and 0 deletions

View File

@ -340,6 +340,13 @@ environment points to a valid, writable folder.""")
# i18n
setupLang(pm, app, opts.lang)
if isLin and pm.glMode() == "auto":
from aqt.utils import gfxDriverIsBroken
if gfxDriverIsBroken():
pm.nextGlMode()
QMessageBox.critical(None, "Error", "Your video driver is incompatible. Please start Anki again, and Anki will switch to a slower, more compatible mode.")
sys.exit(1)
# remaining pm init
pm.ensureProfile()

View File

@ -527,3 +527,48 @@ def versionWithBuild():
except:
build = "dev"
return "%s (%s)" % (appVersion, build)
######################################################################
# adapted from version detection in qutebrowser
def opengl_vendor():
old_context = QOpenGLContext.currentContext()
old_surface = None if old_context is None else old_context.surface()
surface = QOffscreenSurface()
surface.create()
ctx = QOpenGLContext()
ok = ctx.create()
if not ok:
return None
ok = ctx.makeCurrent(surface)
if not ok:
return None
try:
if ctx.isOpenGLES():
# Can't use versionFunctions there
return None
vp = QOpenGLVersionProfile()
vp.setVersion(2, 0)
try:
vf = ctx.versionFunctions(vp)
except ImportError as e:
return None
if vf is None:
return None
return vf.glGetString(vf.GL_VENDOR)
finally:
ctx.doneCurrent()
if old_context and old_surface:
old_context.makeCurrent(old_surface)
def gfxDriverIsBroken():
driver = opengl_vendor()
return driver == "nouveau"