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
icc-effect-5.14.5
Martin Gräßlin 2012-10-13 10:33:38 +02:00
parent 711b434970
commit 388edab9e5
5 changed files with 63 additions and 1 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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;
};

View File

@ -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;
}

View File

@ -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");