diff options
Diffstat (limited to 'qutebrowser/utils/version.py')
-rw-r--r-- | qutebrowser/utils/version.py | 70 |
1 files changed, 63 insertions, 7 deletions
diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index 1ad8b22cf..8dc4ec593 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -31,6 +31,7 @@ import enum import datetime import getpass import typing +import functools import attr import pkg_resources @@ -442,8 +443,8 @@ def version() -> str: if qapp: style = qapp.style() lines.append('Style: {}'.format(style.metaObject().className())) - platform_name = qapp.platformName() - lines.append('Platform plugin: {}'.format(platform_name)) + lines.append('Platform plugin: {}'.format(qapp.platformName())) + lines.append('OpenGL: {}'.format(opengl_info())) importpath = os.path.dirname(os.path.abspath(qutebrowser.__file__)) @@ -487,7 +488,55 @@ def version() -> str: return '\n'.join(lines) -def opengl_vendor() -> typing.Optional[str]: # pragma: no cover +@attr.s +class OpenGLInfo: + + """Information about the OpenGL setup in use.""" + + # If we're using OpenGL ES. If so, no further information is available. + gles = attr.ib(False) # type: bool + + # The name of the vendor. Examples: + # - nouveau + # - "Intel Open Source Technology Center", "Intel", "Intel Inc." + vendor = attr.ib(None) # type: typing.Optional[str] + + # The OpenGL version as a string. See tests for examples. + version_str = attr.ib(None) # type: typing.Optional[str] + + # The parsed version as a (major, minor) tuple of ints + version = attr.ib(None) # type: typing.Optional[typing.Tuple[int, ...]] + + # The vendor specific information following the version number + vendor_specific = attr.ib(None) # type: typing.Optional[str] + + def __str__(self) -> str: + if self.gles: + return 'OpenGL ES' + return '{}, {}'.format(self.vendor, self.version_str) + + @classmethod + def parse(cls, *, vendor: str, version: str) -> 'OpenGLInfo': + if ' ' not in version: + log.misc.warning("Failed to parse OpenGL version (missing space): " + "{}".format(version)) + return cls(vendor=vendor, version_str=version) + + num_str, vendor_specific = version.split(' ', maxsplit=1) + + try: + parsed_version = tuple(int(i) for i in num_str.split('.')) + except ValueError: + log.misc.warning("Failed to parse OpenGL version (parsing int): " + "{}".format(version)) + return cls(vendor=vendor, version_str=version) + + return cls(vendor=vendor, version_str=version, + version=parsed_version, vendor_specific=vendor_specific) + + +@functools.lru_cache(maxsize=1) +def opengl_info() -> typing.Optional[OpenGLInfo]: # pragma: no cover """Get the OpenGL vendor used. This returns a string such as 'nouveau' or @@ -496,10 +545,14 @@ def opengl_vendor() -> typing.Optional[str]: # pragma: no cover """ assert QApplication.instance() - override = os.environ.get('QUTE_FAKE_OPENGL_VENDOR') + # Some setups can segfault in here if we don't do this. + utils.libgl_workaround() + + override = os.environ.get('QUTE_FAKE_OPENGL') if override is not None: log.init.debug("Using override {}".format(override)) - return override + vendor, version = override.split(', ', maxsplit=1) + return OpenGLInfo.parse(vendor=vendor, version=version) old_context = typing.cast(typing.Optional[QOpenGLContext], QOpenGLContext.currentContext()) @@ -522,7 +575,7 @@ def opengl_vendor() -> typing.Optional[str]: # pragma: no cover try: if ctx.isOpenGLES(): # Can't use versionFunctions there - return None + return OpenGLInfo(gles=True) vp = QOpenGLVersionProfile() vp.setVersion(2, 0) @@ -537,7 +590,10 @@ def opengl_vendor() -> typing.Optional[str]: # pragma: no cover log.init.debug("Getting version functions failed!") return None - return vf.glGetString(vf.GL_VENDOR) + vendor = vf.glGetString(vf.GL_VENDOR) + version = vf.glGetString(vf.GL_VERSION) + + return OpenGLInfo.parse(vendor=vendor, version=version) finally: ctx.doneCurrent() if old_context and old_surface: |