From 4406345cd62d3687ce590c357854472f7f906e6c Mon Sep 17 00:00:00 2001 From: Jesse Hall Date: Thu, 1 Dec 2011 11:27:45 -0800 Subject: [PATCH] Disable GLES20Canvas on emu w/o native GL When the emulator is run without '-gpu on', GLES20 isn't supported, so claiming GLES20Canvas is available will lead to catastrophic failure. This change makes GLES20Canvas available when compiled in and either not running on the emulator, or running on the emulator with native GL acceleration enabled. Change-Id: I89c944f9e3c9585224f5aa0877335ea48ea4a468 --- core/jni/android_view_GLES20Canvas.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index 4f75fad684f31..426f4f7cbb598 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -736,7 +737,15 @@ static jboolean android_view_GLES20Canvas_copyLayer(JNIEnv* env, jobject clazz, static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) { #ifdef USE_OPENGL_RENDERER - return JNI_TRUE; + char prop[PROPERTY_VALUE_MAX]; + if (property_get("ro.kernel.qemu", prop, NULL) == 0) { + // not in the emulator + return JNI_TRUE; + } + // In the emulator this property will be set to 1 when hardware GLES is + // enabled, 0 otherwise. On old emulator versions it will be undefined. + property_get("ro.kernel.qemu.gles", prop, "0"); + return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE; #else return JNI_FALSE; #endif