From 388edab9e59e1f8d77985a0121073de4e44b990f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 13 Oct 2012 10:33:38 +0200 Subject: [PATCH] Add support for OpenGL in VirtualBox OpenGL is properly working if there is a direct rendering context. If LIBGL_ALWAYS_INDIRECT is set VirtualBox falls back to Mesa's software rasterizer. So in order to get OpenGL the driver is now whitelisted in the opengltest. GLPlatform is extended to recognize the VirtualBox driver and has new methods to report whether it is a virtual machine and VirtualBox. The detection is rather limited as we don't get access to the underlying hardware, so we do not know whether the features are really supported. We need to trust the driver here in announcing the right extensions. The driver does not provide glxQueryDrawable although it is part of GLX 1.3. A hack is added in the glxbackend to set the function pointer to NULL. This can unfortunately not be done in glxResolveFunctions() as QueryDrawable seems not to be provided by an extension (at least not listed in the OpenGL registry) and getProcAddress resolves a function but it only prints an OpenGL Warning to stderr. As a note: the driver reports that it is using XSHM for GLX_EXT_texture_from_pixmap. REVIEW: 106821 --- glxbackend.cpp | 6 ++++++ libkwineffects/kwinglplatform.cpp | 33 ++++++++++++++++++++++++++++++- libkwineffects/kwinglplatform.h | 14 +++++++++++++ opengltest/opengltest.cpp | 5 +++++ workspace.cpp | 6 ++++++ 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/glxbackend.cpp b/glxbackend.cpp index 8b2360a8b0..24fcbebf74 100644 --- a/glxbackend.cpp +++ b/glxbackend.cpp @@ -112,6 +112,12 @@ void GlxBackend::init() qWarning() << "NO VSYNC! glXGetVideoSync, glXSwapInterval, glXIsDirect" << bool(glXGetVideoSync) << bool(glXSwapInterval) << glXIsDirect(display(), ctxbuffer); } + if (glPlatform->isVirtualBox()) { + // VirtualBox does not support glxQueryDrawable + // this should actually be in kwinglutils_funcs, but QueryDrawable seems not to be provided by an extension + // and the GLPlatform has not been initialized at the moment when initGLX() is called. + glXQueryDrawable = NULL; + } setIsDirectRendering(bool(glXIsDirect(display(), ctxbuffer))); kDebug(1212) << "DB:" << isDoubleBuffer() << ", Direct:" << isDirectRendering() << endl; } diff --git a/libkwineffects/kwinglplatform.cpp b/libkwineffects/kwinglplatform.cpp index b936c79117..ce6c9edfe9 100644 --- a/libkwineffects/kwinglplatform.cpp +++ b/libkwineffects/kwinglplatform.cpp @@ -430,6 +430,8 @@ QString GLPlatform::driverToString(Driver driver) return "softpipe"; case Driver_Llvmpipe: return "LLVMpipe"; + case Driver_VirtualBox: + return "VirtualBox (Chromium)"; default: return "Unknown"; @@ -505,7 +507,8 @@ GLPlatform::GLPlatform() m_supportsGLSL(false), m_limitedGLSL(false), m_textureNPOT(false), - m_limitedNPOT(false) + m_limitedNPOT(false), + m_virtualMachine(false) { } @@ -709,6 +712,19 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface) m_driver = Driver_Swrast; } + // Virtual Hardware + // ==================================================== + else if (m_vendor == "Humper" && m_renderer == "Chromium") { + // Virtual Box + m_driver = Driver_VirtualBox; + + const int index = versionTokens.indexOf("Chromium"); + if (versionTokens.count() > index) + m_driverVersion = parseVersionString(versionTokens.at(index + 1)); + else + m_driverVersion = 0; + } + // Driver/GPU specific features // ==================================================== @@ -769,6 +785,10 @@ void GLPlatform::detect(OpenGLPlatformInterface platformInterface) // Software emulation does not provide GLSL m_limitedGLSL = m_supportsGLSL = false; } + + if (isVirtualBox()) { + m_virtualMachine = true; + } } static void print(const QString &label, const QString &setting) @@ -810,6 +830,7 @@ void GLPlatform::printResults() const print("Requires strict binding:", !m_looseBinding ? "yes" : "no"); print("GLSL shaders:", m_supportsGLSL ? (m_limitedGLSL ? "limited" : "yes") : "no"); print("Texture NPOT support:", m_textureNPOT ? (m_limitedNPOT ? "limited" : "yes") : "no"); + print("Virtual Machine:", m_virtualMachine ? "yes" : "no"); } bool GLPlatform::supports(GLFeature feature) const @@ -908,6 +929,11 @@ bool GLPlatform::isIntel() const return m_chipClass >= I8XX && m_chipClass <= UnknownIntel; } +bool GLPlatform::isVirtualBox() const +{ + return m_driver == Driver_VirtualBox; +} + bool GLPlatform::isSoftwareEmulation() const { return m_driver == Driver_Softpipe || m_driver == Driver_Swrast || m_driver == Driver_Llvmpipe; @@ -943,5 +969,10 @@ bool GLPlatform::isLooseBinding() const return m_looseBinding; } +bool GLPlatform::isVirtualMachine() const +{ + return m_virtualMachine; +} + } // namespace KWin diff --git a/libkwineffects/kwinglplatform.h b/libkwineffects/kwinglplatform.h index 8940681ad3..a961efe9d7 100644 --- a/libkwineffects/kwinglplatform.h +++ b/libkwineffects/kwinglplatform.h @@ -96,6 +96,7 @@ enum Driver { Driver_Swrast, Driver_Softpipe, Driver_Llvmpipe, + Driver_VirtualBox, Driver_Unknown }; @@ -238,12 +239,24 @@ public: */ bool isIntel() const; + /** + * @returns @c true if the "GPU" is a VirtualBox GPU, and @c false otherwise. + * @since 4.10 + **/ + bool isVirtualBox() const; + /** * @returns @c true if OpenGL is emulated in software. * @since 4.7 **/ bool isSoftwareEmulation() const; + /** + * @returns @c true if the driver is known to be from a virtual machine. + * @since 4.10 + **/ + bool isVirtualMachine() const; + /** * @returns the GL_VERSION string as provided by the driver. * @since 4.9 @@ -326,6 +339,7 @@ private: bool m_limitedGLSL: 1; bool m_textureNPOT: 1; bool m_limitedNPOT: 1; + bool m_virtualMachine: 1; static GLPlatform *s_platform; }; diff --git a/opengltest/opengltest.cpp b/opengltest/opengltest.cpp index 17641e2faf..b0b8f59857 100644 --- a/opengltest/opengltest.cpp +++ b/opengltest/opengltest.cpp @@ -125,6 +125,11 @@ int main(int argc, char *argv[]) return 0; } + // Direct context also works with VirtualBox's driver + const GLubyte *renderer = glGetString(GL_RENDERER); + if (strstr((const char *)vendor, "Humper") && strstr((const char *)renderer, "Chromium")) + return 0; + return 1; } diff --git a/workspace.cpp b/workspace.cpp index e86e39e15a..75972d4954 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -2188,6 +2188,12 @@ QString Workspace::supportInformation() const } else { support.append(" no\n"); } + support.append("Virtual Machine: "); + if (platform->isVirtualMachine()) { + support.append(" yes\n"); + } else { + support.append(" no\n"); + } if (effects->compositingType() == OpenGL2Compositing) { support.append("OpenGL 2 Shaders are used\n");