Skip to content

Commit d51ecaf

Browse files
committed
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
1 parent c0e5967 commit d51ecaf

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

opengl/libs/EGL/Loader.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <limits.h>
2424

2525
#include <cutils/log.h>
26+
#include <cutils/properties.h>
2627

2728
#include <EGL/egl.h>
2829

@@ -45,6 +46,39 @@ namespace android {
4546

4647
ANDROID_SINGLETON_STATIC_INSTANCE( Loader )
4748

49+
/* This function is called to check whether we run inside the emulator,
50+
* and if this is the case whether GLES GPU emulation is supported.
51+
*
52+
* Returned values are:
53+
* -1 -> not running inside the emulator
54+
* 0 -> running inside the emulator, but GPU emulation not supported
55+
* 1 -> running inside the emulator, GPU emulation is supported
56+
* through the "emulation" config.
57+
*/
58+
static int
59+
checkGlesEmulationStatus(void)
60+
{
61+
/* We're going to check for the following kernel parameters:
62+
*
63+
* qemu=1 -> tells us that we run inside the emulator
64+
* android.qemu.gles=<number> -> tells us the GLES GPU emulation status
65+
*
66+
* Note that we will return <number> if we find it. This let us support
67+
* more additionnal emulation modes in the future.
68+
*/
69+
char prop[PROPERTY_VALUE_MAX];
70+
int result = -1;
71+
72+
/* First, check for qemu=1 */
73+
property_get("ro.kernel.qemu",prop,"0");
74+
if (atoi(prop) != 1)
75+
return -1;
76+
77+
/* We are in the emulator, get GPU status value */
78+
property_get("ro.kernel.qemu.gles",prop,"0");
79+
return atoi(prop);
80+
}
81+
4882
// ----------------------------------------------------------------------------
4983

5084
Loader::driver_t::driver_t(void* gles)
@@ -94,6 +128,15 @@ Loader::Loader()
94128
{
95129
char line[256];
96130
char tag[256];
131+
132+
/* Special case for GLES emulation */
133+
if (checkGlesEmulationStatus() == 0) {
134+
LOGD("Emulator without GPU support detected. Fallback to software renderer.");
135+
gConfig.add( entry_t(0, 0, "android") );
136+
return;
137+
}
138+
139+
/* Otherwise, use egl.cfg */
97140
FILE* cfg = fopen("/system/lib/egl/egl.cfg", "r");
98141
if (cfg == NULL) {
99142
// default config

0 commit comments

Comments
 (0)