From 4c6c0d428befe1fb648398055ab2ae918fef4eb7 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 18 Dec 2018 19:29:34 +1000 Subject: [PATCH] detect and refuse to run on nouveau --- aqt/__init__.py | 7 +++++++ aqt/utils.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/aqt/__init__.py b/aqt/__init__.py index e8e5b76f9..833101286 100644 --- a/aqt/__init__.py +++ b/aqt/__init__.py @@ -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() diff --git a/aqt/utils.py b/aqt/utils.py index 49fbabfa2..24a4f0e4c 100644 --- a/aqt/utils.py +++ b/aqt/utils.py @@ -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"