summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David 'Digit' Turner <digit@google.com> 2011-09-16 17:33:28 +0200
committer David 'Digit' Turner <digit@google.com> 2011-09-16 17:33:28 +0200
commit5ca449d57fc55e73c85da030fb22920107e6f82c (patch)
treeb262d533aa5e7df0e6300622d1281d73886d9576
parent061ad637f7d17ea3972d9bbb15b80b96e02f47c1 (diff)
opengl: Ensure we only load the GLES emulation library when the emulator supports it.
This patch modifies the libEGL.so loader to only load the emulator-specific EGL/GLES libraries if it detects at runtime that the emulator supports it. This prevents the system crashing when booting the platform image under an old emulator version, or one without GPU emulation enabled. Change-Id: I711b3f0a4ee1f3b080263780726ce7ec28ff11d6
-rw-r--r--opengl/libs/EGL/Loader.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp
index 747c829eda..e16efe34fe 100644
--- a/opengl/libs/EGL/Loader.cpp
+++ b/opengl/libs/EGL/Loader.cpp
@@ -23,6 +23,7 @@
#include <limits.h>
#include <cutils/log.h>
+#include <cutils/properties.h>
#include <EGL/egl.h>
@@ -45,6 +46,39 @@ namespace android {
ANDROID_SINGLETON_STATIC_INSTANCE( Loader )
+/* This function is called to check whether we run inside the emulator,
+ * and if this is the case whether GLES GPU emulation is supported.
+ *
+ * Returned values are:
+ * -1 -> not running inside the emulator
+ * 0 -> running inside the emulator, but GPU emulation not supported
+ * 1 -> running inside the emulator, GPU emulation is supported
+ * through the "emulation" config.
+ */
+static int
+checkGlesEmulationStatus(void)
+{
+ /* We're going to check for the following kernel parameters:
+ *
+ * qemu=1 -> tells us that we run inside the emulator
+ * android.qemu.gles=<number> -> tells us the GLES GPU emulation status
+ *
+ * Note that we will return <number> if we find it. This let us support
+ * more additionnal emulation modes in the future.
+ */
+ char prop[PROPERTY_VALUE_MAX];
+ int result = -1;
+
+ /* First, check for qemu=1 */
+ property_get("ro.kernel.qemu",prop,"0");
+ if (atoi(prop) != 1)
+ return -1;
+
+ /* We are in the emulator, get GPU status value */
+ property_get("ro.kernel.qemu.gles",prop,"0");
+ return atoi(prop);
+}
+
// ----------------------------------------------------------------------------
Loader::driver_t::driver_t(void* gles)
@@ -94,6 +128,15 @@ Loader::Loader()
{
char line[256];
char tag[256];
+
+ /* Special case for GLES emulation */
+ if (checkGlesEmulationStatus() == 0) {
+ LOGD("Emulator without GPU support detected. Fallback to software renderer.");
+ gConfig.add( entry_t(0, 0, "android") );
+ return;
+ }
+
+ /* Otherwise, use egl.cfg */
FILE* cfg = fopen("/system/lib/egl/egl.cfg", "r");
if (cfg == NULL) {
// default config